jxls java excel templates tools
website:http://jxls.sourceforge.net/
Reader:
example:
InputStream xis = new FileInputStream(file);
Workbook wk = Workbook.getWorkbook(xis);
Sheet sheets = wk.getSheet(0);// 获得总 Sheets
int rows = sheets.getRows();
for (int i = 0; i < rows; i++) {
Cell[] cell_domain = sheets.getRow(i); // 获取第i行 所有列形成数组
String str = cell_domain[0].getContents(); //获取第1列的值
}
xis.close();
Wirte:
example:
//Excel模板目录
String templatesDir = "D:/templates";
//写入的目录
String downloadDir = "D:/download";
//文件路径
String templateFileName = templatesDir
+"/excel_template.xls";
String destFileName = downloadDir
+ "/excel_test.xls";
Map<String, Object> beans = new HashMap<String, Object>();
String tt = "测试代码";
beans.put("test",tt); // 对应excel_template里面的 ${test}
List<Entity> list = new ArrayList<Entity>();
list.add(...)
//entity.attributeA 对应excel_template里面的 ${en.attributeA}
//entity.attributeB 对应excel_template里面的 ${en.attributeB}
//循环输出
beans.put("en",list);
XLSTransformer transformer = new XLSTransformer();
transformer.transformXLS(templateFileName, beans,
destFileName);
//实体类
class Entity{
private String attributeA;
private int attributeB;
public String getAttributeA() {
return attributeA;
}
public void setAttributeA(String attributeA) {
this.attributeA = attributeA;
}
public int getAttributeB() {
return attributeB;
}
public void setAttributeB(int attributeB) {
this.attributeB = attributeB;
}
}
浙公网安备 33010602011771号