List of usage examples for org.apache.poi.ss.util SheetUtil getColumnWidth
public static double getColumnWidth(Sheet sheet, int column, boolean useMergedCells)
From source file:uk.co.spudsoft.birt.emitters.excel.handlers.AbstractRealTableHandler.java
License:Open Source License
@Override public void endTable(HandlerState state, ITableContent table) throws BirtException { if (table.getGenerateBy() instanceof GridItemDesign) { endDetailsRow = state.rowNum;// ww w .j a va 2 s. c om } log.debug("Applying bottom border to [", state.rowNum - 1, ",", startCol, "] - [", state.rowNum - 1, ",", startCol + table.getColumnCount() - 1, "]"); state.getSmu().applyBottomBorderToRow(state.getSm(), state.currentSheet, startCol, startCol + table.getColumnCount() - 1, state.rowNum - 1, tableStyle); if (borderDefn != null) { state.removeBorderOverload(borderDefn); } log.debug("Details rows from ", startDetailsRow, " to ", endDetailsRow); if ((startDetailsRow > 0) && (endDetailsRow > startDetailsRow)) { boolean forceAutoColWidths = EmitterServices.booleanOption(state.getRenderOptions(), table, ExcelEmitter.FORCEAUTOCOLWIDTHS_PROP, false); for (int col = 0; col < table.getColumnCount(); ++col) { int oldWidth = state.currentSheet.getColumnWidth(col); if (forceAutoColWidths || (oldWidth == 256 * state.currentSheet.getDefaultColumnWidth())) { FilteredSheet filteredSheet = new FilteredSheet(state.currentSheet, startDetailsRow, Math.min(endDetailsRow, startDetailsRow + 12)); 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 characters if (calcWidth > maxColumnWidth) { calcWidth = maxColumnWidth; } if (calcWidth > oldWidth) { state.currentSheet.setColumnWidth(col, (int) (calcWidth)); } } } } } if ((table.getBookmark() != null) && (state.rowNum > startRow) && (table.getColumnCount() > 1)) { createName(state, prepareName(table.getBookmark()), startRow, 0, state.rowNum - 1, table.getColumnCount() - 1); } if (EmitterServices.booleanOption(state.getRenderOptions(), table, ExcelEmitter.DISPLAYFORMULAS_PROP, false)) { state.currentSheet.setDisplayFormulas(true); } if (!EmitterServices.booleanOption(state.getRenderOptions(), table, ExcelEmitter.DISPLAYGRIDLINES_PROP, true)) { state.currentSheet.setDisplayGridlines(false); } if (!EmitterServices.booleanOption(state.getRenderOptions(), table, ExcelEmitter.DISPLAYROWCOLHEADINGS_PROP, true)) { state.currentSheet.setDisplayRowColHeadings(false); } if (!EmitterServices.booleanOption(state.getRenderOptions(), table, ExcelEmitter.DISPLAYZEROS_PROP, true)) { state.currentSheet.setDisplayZeros(false); } }