Skip to content

Commit

Permalink
Fixing of excel column width calculation (eclipse-birt#1686)
Browse files Browse the repository at this point in the history
  • Loading branch information
speckyspooky committed May 15, 2024
1 parent 9be0079 commit 9218955
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static double widthUnits2Millimetres(int widthUnits) {
*/
public static int millimetres2WidthUnits(double millimetres) {
int pixels = (int) (millimetres * PIXELS_PER_MILLIMETRES);
short widthUnits = (short) (EXCEL_COLUMN_WIDTH_FACTOR * (pixels / UNIT_OFFSET_LENGTH));
int widthUnits = (EXCEL_COLUMN_WIDTH_FACTOR * (pixels / UNIT_OFFSET_LENGTH));
widthUnits += UNIT_OFFSET_MAP[(pixels % UNIT_OFFSET_LENGTH)];
return widthUnits;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ public void startTable(HandlerState state, ITableContent table) throws BirtExcep
log.debug("BIRT table column width: ", col, " = ", width);
int newWidth = state.getSmu().poiColumnWidthFromDimension(width);
int oldWidth = state.currentSheet.getColumnWidth(startCol + col);
if ((oldWidth == 256 * state.currentSheet.getDefaultColumnWidth()) || (newWidth > oldWidth)) {
// calculation excel column max value 255 * 256 excel factor
int maxValue = 255 * 256;
if (newWidth > maxValue) {
state.currentSheet.setColumnWidth(startCol + col, maxValue);
} else if ((oldWidth == 256 * state.currentSheet.getDefaultColumnWidth()) || (newWidth > oldWidth)) {
state.currentSheet.setColumnWidth(startCol + col, newWidth);
}
}
Expand Down

0 comments on commit 9218955

Please sign in to comment.