<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.1.2</version>
</dependency>
Map<String, Object> data = new HashMap<String, Object>(3);
data.put("content", sb.toString());
data.put("indexNames", indexNames);
Map<String, Object> maps = new HashMap<String, Object>(2);
maps.put("indexManage", data);
File file = new File(filePath);
if (!file.exists()) {
// 路径不存在
file.mkdirs();
}
ExcelOutUtil.exportIndexToDirectByTemp(indexNames.size(), maps, "file/指标生成模板.xlsx", formulaIdIn.getFormulaInfoId() + "指标模板.xlsx", new Integer[]{1}, filePath);
四、exportIndexToDirectByTemp具体内容为:
public static void exportIndexToDirectByTemp(Integer indexSize,Map<String, Object> param, String path, String fileName, Integer[] sheetNums, String direct) {
OutputStream out = null;
try {
TemplateExportParams params = new TemplateExportParams(path, true);
//要使用横向遍历必须设置为true
params.setColForEach(true);
params.setStyle(ExcelStyleType.BORDER.getClazz());
//params.setSheetNum(new Integer[]{1, 2, 3, 4});
params.setSheetNum(sheetNums);
Workbook book = ExcelExportUtil.exportExcel(params, param);
setCell(book,indexSize,0);
setCell(book,indexSize,1);
exportToDirect(direct, book, fileName);
} catch (Exception e) {
throw new RuntimeException("导出异常", e);
}
}
//设置边框样式并合并单元格
public static void setCell(Workbook book,Integer indexSize,Integer rowNum){
//CellRangeAddress(第几行开始,第几行结束,第几列开始,第几列结束)
CellRangeAddress craOne = new CellRangeAddress(rowNum, rowNum, 0, indexSize+1);
Sheet sheet = book.getSheetAt(0);
sheet.addMergedRegion(craOne);
Row row = sheet.getRow(rowNum);
CellStyle style = book.createCellStyle();
// 设置边框样式
style.setBorderTop(BorderStyle.THIN);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
for (int i = 1; i <= indexSize+1; i++) {
Cell cell = row.getCell(i);
if (cell == null) {
cell = row.createCell(i);
}
cell.setCellStyle(style);
}
}
五、最终导出结果:
原文地址:https://blog.csdn.net/u012758488/article/details/134788123
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_39190.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。