From 92189558d69bab9b5efda2ff16071e34f3d8ecd8 Mon Sep 17 00:00:00 2001 From: Thomas Gutmann Date: Wed, 15 May 2024 21:45:45 +0200 Subject: [PATCH 1/2] Fixing of excel column width calculation (#1686) --- .../birt/emitters/excel/ClientAnchorConversions.java | 2 +- .../emitters/excel/handlers/AbstractRealTableHandler.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java index 8126a01d04..8987b7f5c4 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/ClientAnchorConversions.java @@ -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; } diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/AbstractRealTableHandler.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/AbstractRealTableHandler.java index 13ce7d3290..63408229f4 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/AbstractRealTableHandler.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/AbstractRealTableHandler.java @@ -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); } } From 454a8d04aa3b149d5a5b7dd2f34e32ae4bba880e Mon Sep 17 00:00:00 2001 From: Thomas Gutmann Date: Thu, 16 May 2024 22:53:47 +0200 Subject: [PATCH 2/2] Fix data type issue of image cell processing --- .../co/spudsoft/birt/emitters/excel/handlers/PageHandler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/PageHandler.java b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/PageHandler.java index bd3070f143..f40302e30d 100644 --- a/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/PageHandler.java +++ b/engine/uk.co.spudsoft.birt.emitters.excel/src/uk/co/spudsoft/birt/emitters/excel/handlers/PageHandler.java @@ -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())) { @@ -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); }