java 通过模板导出excel

1 pom

net.sf.jxls
jxls-core
1.0.6


2

import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import net.sf.jxls.exception.ParsePropertyException; import net.sf.jxls.transformer.XLSTransformer; public class TestExcel { public static void main(String[] args){ String srcFilePath = "D:\\work\\doc\\exceltemplate\\test.xlsx"; Map beanParams = new HashMap(); List product = new ArrayList(); Product producta = new Product(); producta.setNo("123242344534546456456"); producta.setName("我的aaa"); producta.setPrice(103.369); producta.setScale("sdfsgfsgdfgdfg"); producta.setCreated(new Date()); product.add(producta); Product productb = new Product(); productb.setNo("123242344534546456456"); productb.setName("qqqqqq"); productb.setPrice(200.582); productb.setScale("rrrrrrr"); productb.setCreated(new Date()); product.add(productb); beanParams.put("vms", product); String destFilePath = "D:\\work\\doc\\exceltemplate\\simple.xlsx"; try {XLSTransformer transformer = new XLSTransformer(); transformer.transformXLS(srcFilePath, beanParams, destFilePath); } catch (ParsePropertyException e) { e.printStackTrace(); } catch (InvalidFormatException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }


模板下载


【java 通过模板导出excel】

    推荐阅读