List of usage examples for org.apache.poi.hssf.converter AbstractExcelUtils getColumnWidthInPx
public static int getColumnWidthInPx(int widthUnits)
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
/** * Sets the column to automatically adjust the column width to fit the * largest cell content within the column. This is a POI feature, and is * meant to be called after all the data for the target column has been * written. See {@link Sheet#autoSizeColumn(int)}. * <p>/*from w w w . j ava2 s .co m*/ * This does not take into account cells that have custom Vaadin components * inside them. * * @param columnIndex * Index of the target column, 0-based */ public void autofitColumn(int columnIndex) { final Sheet activeSheet = getActiveSheet(); activeSheet.autoSizeColumn(columnIndex); getState().colW[columnIndex] = AbstractExcelUtils .getColumnWidthInPx(activeSheet.getColumnWidth(columnIndex)); getCellValueManager().clearCacheForColumn(columnIndex + 1); getCellValueManager().loadCellData(firstRow, columnIndex + 1, lastRow, columnIndex + 1); if (hasSheetOverlays()) { reloadImageSizesFromPOI = true; loadOrUpdateOverlays(); } }
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
/** * Hides or shows the given column, see/*from www.jav a2s . com*/ * {@link Sheet#setColumnHidden(int, boolean)}. * * @param columnIndex * Index of the target column, 0-based * @param hidden * True to hide the target column, false to show it. */ public void setColumnHidden(int columnIndex, boolean hidden) { getActiveSheet().setColumnHidden(columnIndex, hidden); if (hidden && !getState().hiddenColumnIndexes.contains(columnIndex + 1)) { getState().hiddenColumnIndexes.add(columnIndex + 1); getState().colW[columnIndex] = 0; } else if (!hidden && getState().hiddenColumnIndexes.contains(columnIndex + 1)) { getState().hiddenColumnIndexes.remove(getState().hiddenColumnIndexes.indexOf(columnIndex + 1)); getState().colW[columnIndex] = AbstractExcelUtils .getColumnWidthInPx(getActiveSheet().getColumnWidth(columnIndex)); getCellValueManager().clearCacheForColumn(columnIndex + 1); getCellValueManager().loadCellData(firstRow, columnIndex + 1, lastRow, columnIndex + 1); } if (hasSheetOverlays()) { reloadImageSizesFromPOI = true; loadOrUpdateOverlays(); } }