Skip to content

Commit

Permalink
Merge pull request #279 from liaochong/Hotfix/3.9.7
Browse files Browse the repository at this point in the history
Hotfix/3.9.7
  • Loading branch information
liaochong authored Oct 18, 2020
2 parents 81f39ae + 9665721 commit 643399c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.github.liaochong</groupId>
<artifactId>myexcel</artifactId>
<version>3.9.6</version>
<version>3.9.7</version>
<packaging>jar</packaging>

<name>myexcel</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.github.liaochong.myexcel.core.parser.Tr;
import com.github.liaochong.myexcel.exception.ExcelBuildException;
import com.github.liaochong.myexcel.utils.FileExportUtil;
import com.github.liaochong.myexcel.utils.StringUtil;
import com.github.liaochong.myexcel.utils.TdUtil;
import com.github.liaochong.myexcel.utils.TempFileOperator;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Sheet;
Expand All @@ -32,6 +34,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -117,13 +120,6 @@ public void start(Table table, Workbook workbook) {
this.workbook = workbook;
}
startTime = System.currentTimeMillis();
if (this.workbook == null) {
workbookType(WorkbookType.SXLSX);
}
if (isHssf) {
maxRowCountOfSheet = XLS_MAX_ROW_COUNT;
}
initCellStyle(this.workbook);
if (table != null) {
sheetName = this.getRealSheetName(table.getCaption());
}
Expand Down Expand Up @@ -155,6 +151,13 @@ public void append(Tr tr) {

private void receive() {
try {
if (this.workbook == null) {
workbookType(WorkbookType.SXLSX);
}
if (isHssf) {
maxRowCountOfSheet = XLS_MAX_ROW_COUNT;
}
initCellStyle(this.workbook);
receiveThread = Thread.currentThread();
Tr tr = this.getTrFromQueue();
this.sheet = this.createSheet(sheetName);
Expand Down Expand Up @@ -206,13 +209,21 @@ private void setTdStyle(Tr tr) {
return;
}
context.styleParser.toggle();
// 是否为自定义宽度
boolean isCustomWidth = !Objects.equals(tr.getColWidthMap(), Collections.emptyMap());
for (int i = 0, size = tr.getTdList().size(); i < size; i++) {
Td td = tr.getTdList().get(i);
if (td.isTh()) {
td.setStyle(context.styleParser.getTitleStyle("title&" + td.getCol()));
} else {
td.setStyle(context.styleParser.getCellStyle(i, td.getTdContentType(), td.getFormat()));
}
if (isCustomWidth) {
String width = td.getStyle().get("width");
if (StringUtil.isNotBlank(width)) {
tr.getColWidthMap().put(i, TdUtil.getValue(width));
}
}
}
}

Expand Down

0 comments on commit 643399c

Please sign in to comment.