Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of excel column width calculation (#1686) #1687

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading