Skip to content

Commit

Permalink
Improve the xlsx column auto fit (#1553) (#1557)
Browse files Browse the repository at this point in the history
  • Loading branch information
speckyspooky authored Jan 27, 2024
1 parent f32bef1 commit 7cd02fe
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,18 @@ public void endTable(HandlerState state, ITableContent table) throws BirtExcepti
double calcWidth = SheetUtil.getColumnWidth(filteredSheet, col, false);

if (calcWidth > 1.0) {
calcWidth *= 256;
int maxColumnWidth = 255 * 256; // The maximum column width for an individual cell is 255
state.currentSheet.autoSizeColumn(col, true);
calcWidth = state.currentSheet.getColumnWidth(col) * 1.15; // offset to handle width differences of apache poi
int maxColumnWidth = 255 * 256; // The maximum column width for an individual cell is 255
// characters
if (calcWidth > maxColumnWidth) {
calcWidth = maxColumnWidth;
}
if (calcWidth > oldWidth) {
state.currentSheet.setColumnWidth(col, (int) (calcWidth));
state.currentSheet.setColumnWidth(col, (int) calcWidth);
}
} else {
state.currentSheet.autoSizeColumn(col, true);
}
}
}
Expand Down

0 comments on commit 7cd02fe

Please sign in to comment.