easyexcel icon indicating copy to clipboard operation
easyexcel copied to clipboard

填充表格问题

Open RocChing opened this issue 6 years ago • 2 comments

建议先去看文档 快速开始 、常见问题 触发场景描述

我用来填充表格的模板是用easyexcel生成的;然后用生成的模板填充数据后,模板那行数据还在占用了第一行数据;

触发Bug的代码

  
 String templatePath = "https://*****/pactera/res/template_score.xlsx";
                String tempPath = FileUtil.mkdirs(CommonInfo.RES_EXAM_PAPER_TEMP_UPLOAD_PATH);
                String fileName = paper.getSubjectCode() + "_template_score" + System.currentTimeMillis() + ".xlsx";
                String path = tempPath + File.separator + fileName;
                URLDataSource dataSource = new URLDataSource(new URL(templatePath));
                log.info("the path value is: {}", path);

//生成模板
EasyExcel.write(path).autoCloseStream(true).withTemplate(dataSource.getInputStream()).registerWriteHandler(new ExcelColumnWidthStyleStrategy()).sheet().doWrite(infoTemplate.getDataList());

                ExcelMergeCellStrategy mergeCellStrategy = new ExcelMergeCellStrategy(info.getExtraList());
                String fileName2 =paper.getSubjectCode() + "_template_score" + System.currentTimeMillis() + ".xlsx";
                String path2 = tempPath + File.separator + fileName2;

                log.info("the path value is: {}", path2);
                log.info(JSON.toJSONString(info.getDataList()));
//填充模板
                ExcelWriter excelWriter = EasyExcel.write(path2).withTemplate(path).registerWriteHandler(new ExcelColumnWidthStyleStrategy()).registerWriteHandler(mergeCellStrategy).needHead(false).build();
                WriteSheet writeSheet = EasyExcel.writerSheet().build();
                excelWriter.fill(new FillWrapper("data", info.getDataList()), writeSheet);
                excelWriter.finish();

提示的异常或者没有达到的效果

生成的模板如下: image

填充完的表格如下: image

麻烦作者有空看看;

RocChing avatar Jun 13 '20 05:06 RocChing

我也是,模板中的表达式不仅没有消失,而且还占用了内容的第一行。

Myloveisyou1 avatar Jun 23 '20 07:06 Myloveisyou1

生成模板的时候 使用inmoery=ture。参照:https://www.yuque.com/easyexcel/faq/ocu86k

zhuangjiaju avatar Jun 23 '20 12:06 zhuangjiaju