use of com.github.liaochong.myexcel.core.strategy.WidthStrategy in project myexcel by liaochong.
the class HtmlToExcelFactory method setTdOfTable.
/**
* 设置所有单元格,自适应列宽,单元格最大支持字符长度255
*/
private void setTdOfTable(Table table, Sheet sheet) {
int maxColIndex = 0;
if (WidthStrategy.isAutoWidth(widthStrategy) && !table.trList.isEmpty()) {
maxColIndex = table.trList.parallelStream().mapToInt(tr -> tr.tdList.stream().mapToInt(td -> td.col).max().orElse(0)).max().orElse(0);
}
Map<Integer, Integer> colMaxWidthMap = this.getColMaxWidthMap(table.trList);
// one sheet情况下重置非首个table的tr、td索引下标
int sheetLastRowIndex = sheet.getLastRowNum();
if (SheetStrategy.isOneSheet(sheetStrategy)) {
if (sheetLastRowIndex != 0) {
sheetLastRowIndex += 1;
}
}
for (int i = 0, size = table.trList.size(); i < size; i++) {
Tr tr = table.trList.get(i);
this.updateTrIndex(tr, sheetLastRowIndex);
this.createRow(tr, sheet);
tr.tdList = null;
}
table.trList = null;
this.setColWidth(colMaxWidthMap, sheet, maxColIndex);
}
Aggregations