Excel的模板导出框架
jxls 目前为2.3.0版本 官方网站
ExcelUtils 官方网站
easypoi 官网网站
jxls 1.6 pom
org.jxls
jxls-jdk1.6
2.2.9
org.jxls
jxls-poi-jdk1.6
1.0.8
org.jxls
jxls
2.3.0
org.jxls
jxls-jexcel
1.0.6
import org.jxls.area.Area;
import org.jxls.builder.AreaBuilder;
import org.jxls.builder.xls.XlsCommentAreaBuilder;
import org.jxls.common.CellRef;
import org.jxls.common.Context;
import org.jxls.expression.ExpressionEvaluator;
import org.jxls.expression.JexlExpressionEvaluator;
import org.jxls.transform.Transformer;
import org.jxls.transform.poi.PoiTransformer;
import org.jxls.util.JxlsHelper;
import org.jxls.util.TransformerFactory;
import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public static void main(String[] args) throws Exception {
InputStream is = new FileInputStream(new File("jexl_custom_function_template.xlsx"));
OutputStream os = new FileOutputStream(new File("out.xlsx"));
//Transformer transformer = TransformerFactory.createTransformer(is, os);
PoiTransformer transformer = PoiTransformer.createTransformer(is, os);
ExpressionEvaluator expressionEvaluator = new VelocityExpressionEvaluator();
transformer.getTransformationConfig().setExpressionEvaluator(expressionEvaluator);
AreaBuilder areaBuilder = new XlsCommentAreaBuilder(transformer);
List xlsAreaList = areaBuilder.build();
Area xlsArea = xlsAreaList.get(0);
List strings = Arrays.asList(new String[]{"a", "b", "c","d"});
Context context = new Context();
context.putVar("username", "a");
context.putVar("list", strings);
xlsArea.applyAt(new CellRef("Sheet1!A1"), context);
transformer.write();
}