Skip to content

Commit

Permalink
Fix of excel column width calculation (#1686) (#1687)
Browse files Browse the repository at this point in the history
* Fixing of excel column width calculation (#1686)
* Fix data type issue of image cell processing
  • Loading branch information
speckyspooky authored May 17, 2024
1 parent ce95915 commit beb7ad3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private void processCellImage(HandlerState state, Drawing<?> drawing, CellImage
// Get image width
int endCol = cell.getColumnIndex();
double lastColWidth = ClientAnchorConversions
.widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
.widthUnits2Millimetres(state.currentSheet.getColumnWidth(endCol)) + 2.0;
int dx = smu.anchorDxFromMM(lastColWidth, lastColWidth);
double mmWidth = 0.0;
if (smu.isAbsolute(image.getWidth())) {
Expand All @@ -344,7 +344,7 @@ private void processCellImage(HandlerState state, Drawing<?> drawing, CellImage
int endColLimit = cellImage.spanColumns ? 256 : mergedRegion.getLastColumn();
for (endCol = cell.getColumnIndex(); mmAccumulatedWidth < mmWidth && endCol < endColLimit; ++endCol) {
lastColWidth = ClientAnchorConversions
.widthUnits2Millimetres((short) state.currentSheet.getColumnWidth(endCol)) + 2.0;
.widthUnits2Millimetres(state.currentSheet.getColumnWidth(endCol)) + 2.0;
mmAccumulatedWidth += lastColWidth;
log.debug("lastColWidth = ", lastColWidth, "; mmAccumulatedWidth = ", mmAccumulatedWidth);
}
Expand Down

0 comments on commit beb7ad3

Please sign in to comment.