package org.jeecg.modules.caiwu.util.excel;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class excel {
@Test
public void fe_map() throws Exception {
TemplateExportParams params = new TemplateExportParams(
"C:\\Users\\oshait24\\Desktop\\专项支出用款申请书_map.xls");
Map<String, Object> map = new HashMap<String, Object>();
map.put("date", "2014-12-25");
map.put("money", 2000000.00);
map.put("upperMoney", "贰佰万");
map.put("company", "执笔潜行科技有限公司");
map.put("bureau", "财政局");
map.put("person", "JueYue");
map.put("phone", "1879740****");
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
for (int i = 0; i < 4; i++) {
Map<String, String> lm = new HashMap<String, String>();
lm.put("id", i + 1 + "");
lm.put("zijin", i * 10000 + "");
lm.put("bianma", "A001");
lm.put("mingcheng", "设计");
lm.put("xiangmumingcheng", "EasyPoi " + i + "期");
lm.put("quancheng", "开源项目");
lm.put("sqje", i * 10000 + "");
lm.put("hdje", i * 10000 + "");
listMap.add(lm);
}
map.put("maplist", listMap);
Workbook workbook = ExcelExportUtil.exportExcel(params, map);
File savefile = new File("C:Desktop\\");
if (!savefile.exists()) {
savefile.mkdirs();
}
FileOutputStream fos = new FileOutputStream("C:\\Desktop\\专项支出用款申请书.xls");
workbook.write(fos);
fos.close();
}
}
java制作excel模板并根据模板导出
最新推荐文章于 2024-08-07 17:06:19 发布
这是一个Java代码示例,展示了如何利用EasyPoi库和模板导出Excel文件,用于创建专项支出用款申请书。代码创建了一个Map对象填充数据,包括日期、金额、公司名等信息,并生成了一个包含多条明细数据的列表,最后将这些数据写入到Excel模板中并保存到指定路径。
摘要由CSDN通过智能技术生成