隨筆-69  評論-0  文章-5  trackbacks-0
          自定義一個單元格處理器
          import?java.util.Map;

          import?org.apache.poi.hssf.usermodel.HSSFCell;
          import?org.apache.poi.hssf.usermodel.HSSFCellStyle;
          import?org.apache.poi.hssf.usermodel.HSSFFont;
          import?org.apache.poi.hssf.usermodel.HSSFWorkbook;
          import?org.jxls.Cell;
          import?org.jxls.CellProcessor;

          public?class?CustomCellProcessor?implements?CellProcessor?{

          ????
          public?void?processCell(Cell?cell,?Map?arg1)?{
          ????????
          ????????HSSFWorkbook?wb
          =new?HSSFWorkbook();
          ????????HSSFFont?font?
          =?wb.createFont();?
          ????????
          ????????font.setFontHeightInPoints((
          short)24);?
          ????????font.setFontName(
          "宋體");?
          ????????font.setItalic(
          true);?
          ????????HSSFCellStyle?style?
          =?wb.createCellStyle();?
          ????????style.setFont(font);
          ????????
          if(null!=cell.getHssfCell()){
          ????????????cell.getHssfCell().setCellStyle(style);
          ????????????cell.getHssfCell().setEncoding(HSSFCell.ENCODING_UTF_16);
          ????????}

          ????}


          }

          然后
          ?1List?persons=new?ArrayList();
          ?2????????
          ?3????????persons.add(new?Person(1,"liunix","liunix.com@163.com",new?Date()));
          ?4????????persons.add(new?Person(2,"劉家輝","liunix.com@163.com",new?Date()));
          ?5????????persons.add(new?Person(3,"liunix","liunix.com@163.com",new?Date()));
          ?6????????persons.add(new?Person(5,"liunix","liunix.com@163.com",new?Date()));
          ?7????????persons.add(new?Person(7,"liunix","liunix.com@163.com",new?Date()));
          ?8????????persons.add(new?Person(9,"liunix","liunix.com@163.com",new?Date()));
          ?9????????persons.add(new?Person(11,"liunix","liunix.com@163.com",new?Date()));
          10????????persons.add(new?Person(135,"liunix","liunix.com@163.com",new?Date()));
          11????????
          12????????Map?beans=new?HashMap();
          13????????beans.put("persons",persons);
          14????????XLSTransformer?transformer?=?new?XLSTransformer();
          15????????
          16????????transformer.registerCellProcessor(new?CustomCellProcessor());
          17????????transformer.transformXLS("E:/myeclipse/excel/src/test1/person_temp.xls",?beans,?"E:/myeclipse/excel/src/test1/person_dest.xls");
          之類的代碼調用之
          posted on 2006-04-14 18:03 liunix 閱讀(1147) 評論(0)  編輯  收藏 所屬分類: integration

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 绵竹市| 贡觉县| 东兰县| 岐山县| 宾川县| 长丰县| 洱源县| 乌拉特中旗| 承德市| 余干县| 马龙县| 莫力| 兴城市| 三亚市| 德令哈市| 普兰店市| 晋中市| 淮南市| 延吉市| 随州市| 修武县| 武宁县| 鄂州市| 兴国县| 陵水| 象州县| 郯城县| 通化县| 布拖县| 浦北县| 大冶市| 高碑店市| 淳化县| 东山县| 新晃| 三河市| 芦溪县| 临澧县| 永川市| 哈巴河县| 南阳市|