Skip to content

Commit fe2b937

Browse files
authored
Merge pull request #376 from liaochong/Hotfix/4.2.2
Hotfix/4.2.2
2 parents 8859aad + 5fb4196 commit fe2b937

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>com.github.liaochong</groupId>
1313
<artifactId>myexcel</artifactId>
14-
<version>4.2.1</version>
14+
<version>4.2.2</version>
1515
<packaging>jar</packaging>
1616

1717
<name>myexcel</name>

src/main/java/com/github/liaochong/myexcel/core/AbstractSimpleExcelBuilder.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,11 @@ protected List<Tr> createThead() {
241241
}
242242
tdLists.add(tds);
243243
}
244-
245244
// 调整rowSpan
246245
for (List<Td> tdList : tdLists) {
247246
Td last = tdList.get(tdList.size() - 1);
248247
last.setRowSpan(titleLevel - last.row);
249248
}
250-
251249
// 调整colSpan
252250
for (int i = 0; i < titleLevel; i++) {
253251
int level = i;
@@ -300,15 +298,15 @@ protected List<Tr> createThead() {
300298
boolean isComputeAutoWidth = WidthStrategy.isComputeAutoWidth(configuration.widthStrategy);
301299
rowTds.forEach((k, v) -> {
302300
Tr tr = new Tr(k, configuration.titleRowHeight);
303-
tr.colWidthMap = isComputeAutoWidth ? new HashMap<>(titles.size()) : Collections.emptyMap();
304-
List<Td> tds = v.stream().sorted(Comparator.comparing(td -> td.col))
301+
tr.colWidthMap = isComputeAutoWidth || !customWidthMap.isEmpty() ? new HashMap<>(titles.size()) : Collections.emptyMap();
302+
tr.tdList = v.stream().sorted(Comparator.comparing(td -> td.col))
305303
.peek(td -> {
306304
if (isComputeAutoWidth) {
307305
tr.colWidthMap.put(td.col, TdUtil.getStringWidth(td.content, 0.25));
308306
}
309307
})
310308
.collect(Collectors.toList());
311-
tr.tdList = tds;
309+
tr.colWidthMap.putAll(customWidthMap);
312310
trs.add(tr);
313311
});
314312
return trs;
@@ -344,7 +342,7 @@ protected Tr createTr(List<Pair<? extends Class, ?>> contents) {
344342
this.setTdWidth(tr.colWidthMap, td);
345343
return td;
346344
}).collect(Collectors.toList());
347-
customWidthMap.forEach(tr.colWidthMap::put);
345+
tr.colWidthMap.putAll(customWidthMap);
348346
tr.tdList = tdList;
349347
return tr;
350348
}

0 commit comments

Comments
 (0)