自定义一个单元格处理器
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);
}
}

}然后
1
List 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 阅读(1151)
评论(0) 编辑 收藏 所属分类:
integration