Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

动态表头时,内容单元格的样式不生效的bug #1347

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void afterCellDataConverted(WriteSheetHolder writeSheetHolder, WriteTable
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder,
List<CellData> cellDataList, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
if (isHead == null || head == null) {
if (isHead == null) {
return;
}
if (isHead) {
Expand Down
16 changes: 10 additions & 6 deletions src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ public void annotationStyleWrite() {
@Test
public void handlerStyleWrite() {
String fileName = TestFileUtil.getPath() + "handlerStyleWrite" + System.currentTimeMillis() + ".xlsx";
HorizontalCellStyleStrategy horizontalCellStyleStrategy = newHorizontalCellStyleStrategy();

// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(fileName, DemoData.class).registerWriteHandler(horizontalCellStyleStrategy).sheet("模板")
.doWrite(data());
}

private HorizontalCellStyleStrategy newHorizontalCellStyleStrategy() {
// 头的策略
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// 背景设置为红色
Expand All @@ -315,12 +323,7 @@ public void handlerStyleWrite() {
contentWriteFont.setFontHeightInPoints((short)20);
contentWriteCellStyle.setWriteFont(contentWriteFont);
// 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
HorizontalCellStyleStrategy horizontalCellStyleStrategy =
new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);

// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(fileName, DemoData.class).registerWriteHandler(horizontalCellStyleStrategy).sheet("模板")
.doWrite(data());
return new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
}

/**
Expand Down Expand Up @@ -392,6 +395,7 @@ public void dynamicHeadWrite() {
EasyExcel.write(fileName)
// 这里放入动态头
.head(head()).sheet("模板")
.registerWriteHandler(newHorizontalCellStyleStrategy())
// 当然这里数据也可以用 List<List<String>> 去传入
.doWrite(data());
}
Expand Down