-
Notifications
You must be signed in to change notification settings - Fork 473
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Search before asking
- I searched in the issues and found nothing similar.
Fastexcel version
1.3.0
JDK version
1.8
Operating system
win11
Minimal reproduce step
根据文档示例, 无法合并单元格
代码片段
String fileName = "测试对齐报告_" + Instant.now().toEpochMilli() + ".xlsx";
response.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
try {
fileName = URLEncoder.encode(fileName, "UTF-8");
} catch (UnsupportedEncodingException e) {
log.error("编码异常", e);
Assert.justFail("编码异常");
}
response.addHeader("Access-Control-Expose-Headers", "content-disposition");
response.setHeader("content-disposition", "attachment;fileName=" + fileName);
try {
FastExcel.write(response.getOutputStream())
.registerWriteHandler(new AbstractMergeStrategy() {
@Override
protected void merge(Sheet sheet, Cell cell, Head head, Integer integer) {
// Custom merge rules
sheet.addMergedRegion(new CellRangeAddress(3, 4, 3, 4));
}
})
.sheet("测试")
.doWrite(Arrays.asList(Arrays.asList(1, 1, 1, 1, 1, 1),
Arrays.asList(1, 1, 1, 1, 1, 1),
Arrays.asList(1, 1, 1, 1, 1, 1),
Arrays.asList(1, 1, 1, 1, 1, 1),
Arrays.asList(1, 1, 1, 1, 1, 1)));
} catch (IOException e) {
throw new RuntimeException(e);
}结果:
Cannot add merged region D4:E5 to sheet because it overlaps with an existing merged region (D4:E5).
@Override
protected void merge(Sheet sheet, Cell cell, Head head, Integer integer) {
// Custom merge rules
sheet.addMergedRegion(new CellRangeAddress(3, 4, 3, 4));
}不论这里面写什么单元格, 都会报相应的错误, 总之就是不能合并
如果使用addMergedRegionUnsafe则可以成功合并, 但是打开文件时会出现文件修复选项, 不可取
What did you expect to see?
成功合并单元格
What did you see instead?
如果不能很快解决的话, 有没有什么替代方案实现这个功能
ps: 合并的单元格是不固定的, 自定义的, 需要业务代码来动态生成, 所以需要灵活, 非注解类型
Anything else?
No response
Are you willing to submit a PR?
- I'm willing to submit a PR!
cgs-aterwedow
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested