diff --git a/pom.xml b/pom.xml index 92bb4d9b..15fa8a4b 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.github.liaochong myexcel - 4.2.1 + 4.2.2 jar myexcel diff --git a/src/main/java/com/github/liaochong/myexcel/core/AbstractSimpleExcelBuilder.java b/src/main/java/com/github/liaochong/myexcel/core/AbstractSimpleExcelBuilder.java index 22e83a30..cb95c98f 100644 --- a/src/main/java/com/github/liaochong/myexcel/core/AbstractSimpleExcelBuilder.java +++ b/src/main/java/com/github/liaochong/myexcel/core/AbstractSimpleExcelBuilder.java @@ -241,13 +241,11 @@ protected List createThead() { } tdLists.add(tds); } - // 调整rowSpan for (List tdList : tdLists) { Td last = tdList.get(tdList.size() - 1); last.setRowSpan(titleLevel - last.row); } - // 调整colSpan for (int i = 0; i < titleLevel; i++) { int level = i; @@ -300,15 +298,15 @@ protected List createThead() { boolean isComputeAutoWidth = WidthStrategy.isComputeAutoWidth(configuration.widthStrategy); rowTds.forEach((k, v) -> { Tr tr = new Tr(k, configuration.titleRowHeight); - tr.colWidthMap = isComputeAutoWidth ? new HashMap<>(titles.size()) : Collections.emptyMap(); - List tds = v.stream().sorted(Comparator.comparing(td -> td.col)) + tr.colWidthMap = isComputeAutoWidth || !customWidthMap.isEmpty() ? new HashMap<>(titles.size()) : Collections.emptyMap(); + tr.tdList = v.stream().sorted(Comparator.comparing(td -> td.col)) .peek(td -> { if (isComputeAutoWidth) { tr.colWidthMap.put(td.col, TdUtil.getStringWidth(td.content, 0.25)); } }) .collect(Collectors.toList()); - tr.tdList = tds; + tr.colWidthMap.putAll(customWidthMap); trs.add(tr); }); return trs; @@ -344,7 +342,7 @@ protected Tr createTr(List> contents) { this.setTdWidth(tr.colWidthMap, td); return td; }).collect(Collectors.toList()); - customWidthMap.forEach(tr.colWidthMap::put); + tr.colWidthMap.putAll(customWidthMap); tr.tdList = tdList; return tr; }