List of usage examples for org.apache.poi.ss.usermodel Row getZeroHeight
boolean getZeroHeight();
From source file:com.runwaysdk.dataaccess.io.excel.ErrorSheet.java
License:Open Source License
public void addRow(Row _row) { Row row = this.errorSheet.createRow(count++); row.setZeroHeight(_row.getZeroHeight()); row.setHeight(_row.getHeight());// w w w .j av a2 s . co m CellStyle style = _row.getRowStyle(); if (style != null) { Workbook workbook = row.getSheet().getWorkbook(); CellStyle clone = workbook.createCellStyle(); clone.cloneStyleFrom(style); row.setRowStyle(clone); } Iterator<Cell> cellIterator = _row.cellIterator(); while (cellIterator.hasNext()) { Cell oldCell = cellIterator.next(); Cell newCell = row.createCell(oldCell.getColumnIndex()); int cellType = oldCell.getCellType(); if (cellType == Cell.CELL_TYPE_FORMULA) { cellType = oldCell.getCachedFormulaResultType(); } switch (cellType) { case Cell.CELL_TYPE_BOOLEAN: newCell.setCellValue(oldCell.getBooleanCellValue()); break; case Cell.CELL_TYPE_NUMERIC: newCell.setCellValue(oldCell.getNumericCellValue()); break; case Cell.CELL_TYPE_STRING: newCell.setCellValue(oldCell.getRichStringCellValue()); break; } } }
From source file:com.vaadin.addon.spreadsheet.command.RowData.java
public void copy(int rowIndex) { isCopied = true;/*from w w w .ja v a 2 s . c om*/ this.rowIndex = rowIndex; this.maxCol = spreadsheet.getLastColumn(); cellsData.clear(); mergedCells.clear(); commentsWithoutCell.clear(); Row row = spreadsheet.getActiveSheet().getRow(rowIndex); height = row == null ? null : row.getZeroHeight() ? 0.0F : row.getHeightInPoints(); if (row != null) { copyCellsData(row); } Sheet sheet = spreadsheet.getActiveSheet(); for (int i = 0; i < sheet.getNumMergedRegions(); i++) { CellRangeAddress mergedRegion = sheet.getMergedRegion(i); if (mergedRegion.getFirstRow() == rowIndex) { mergedCells.add(mergedRegion); } } }
From source file:com.vaadin.addon.spreadsheet.command.SizeChangeCommand.java
License:Open Source License
/** * Returns the current height/width of the target row/column. * //from ww w. j a v a 2s.c om * @param index * row/column index, 0-based * @return current height for row OR width for column */ private Object getCurrentValue(int index) { if (type == Type.COLUMN) { if (getSheet().isColumnHidden(index)) { return 0; } else { return ExcelToHtmlUtils.getColumnWidthInPx(getSheet().getColumnWidth(index)); } } else if (type == Type.ROW) { Row row = getSheet().getRow(index); // null rows use default row height // null height marks default height return row == null ? null : row.getZeroHeight() ? 0.0F : row.getHeightInPoints(); } return null; }
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
/** * Shifts rows between startRow and endRow n number of rows. If you use a * negative number for n, the rows will be shifted upwards. This method * ensures that rows can't wrap around.//from w w w.j av a 2 s.c o m * <p> * If you are adding / deleting rows, you might want to change the number of * visible rows rendered {@link #getRows()} with {@link #setMaxRows(int)}. * <p> * See {@link Sheet#shiftRows(int, int, int, boolean, boolean)}. * * @param startRow * The first row to shift, 0-based * @param endRow * The last row to shift, 0-based * @param n * Number of rows to shift, positive numbers shift down, negative * numbers shift up. * @param copyRowHeight * True to copy the row height during the shift * @param resetOriginalRowHeight * True to set the original row's height to the default */ public void shiftRows(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight) { Sheet sheet = getActiveSheet(); int lastNonBlankRow = getLastNonBlankRow(sheet); sheet.shiftRows(startRow, endRow, n, copyRowHeight, resetOriginalRowHeight); // need to re-send the cell values to client // remove all cached cell data that is now empty getFormulaEvaluator().clearAllCachedResultValues(); int start = n < 0 ? Math.max(lastNonBlankRow, startRow) : startRow; int end = n < 0 ? endRow : startRow + n - 1; valueManager.updateDeletedRowsInClientCache(start + 1, end + 1); int firstAffectedRow = n < 0 ? startRow + n : startRow; int lastAffectedRow = n < 0 ? endRow : endRow + n; if (copyRowHeight || resetOriginalRowHeight) { // might need to increase the size of the row heights array int oldLength = getState(false).rowH.length; int neededLength = endRow + n + 1; if (n > 0 && oldLength < neededLength) { getState().rowH = Arrays.copyOf(getState().rowH, neededLength); } for (int i = firstAffectedRow; i <= lastAffectedRow; i++) { Row row = sheet.getRow(i); if (row != null) { if (row.getZeroHeight()) { getState().rowH[i] = 0f; } else { getState().rowH[i] = row.getHeightInPoints(); } } else { getState().rowH[i] = sheet.getDefaultRowHeightInPoints(); } } } if (hasSheetOverlays()) { reloadImageSizesFromPOI = true; } // need to shift the cell styles, clear and update // need to go -1 and +1 because of shifted borders.. final ArrayList<Cell> cellsToUpdate = new ArrayList<Cell>(); for (int r = (firstAffectedRow - 1); r <= (lastAffectedRow + 1); r++) { if (r < 0) { r = 0; } Row row = sheet.getRow(r); final Integer rowIndex = new Integer(r + 1); if (row == null) { valueManager.updateDeletedRowsInClientCache(rowIndex, rowIndex); if (getState(false).hiddenRowIndexes.contains(rowIndex)) { getState().hiddenRowIndexes.remove(rowIndex); } for (int c = 0; c < getState().cols; c++) { styler.clearCellStyle(r, c); } } else { if (row.getZeroHeight()) { getState().hiddenRowIndexes.add(rowIndex); } else if (getState(false).hiddenRowIndexes.contains(rowIndex)) { getState().hiddenRowIndexes.remove(rowIndex); } for (int c = 0; c < getState().cols; c++) { Cell cell = row.getCell(c); if (cell == null) { styler.clearCellStyle(r, c); if (r <= lastNonBlankRow + n) { // There might be a pre-shift value for this cell in // client-side and should be overwritten cell = row.createCell(c); cellsToUpdate.add(cell); } } else { cellsToUpdate.add(cell); } } } } rowsMoved(firstAffectedRow, lastAffectedRow, n); for (Cell cell : cellsToUpdate) { styler.cellStyleUpdated(cell, false); markCellAsUpdated(cell, false); } styler.loadCustomBorderStylesToState(); updateMarkedCells(); // deleted and formula cells and style selectors updateRowAndColumnRangeCellData(firstRow, firstColumn, lastRow, lastColumn); // shifted area values updateMergedRegions(); CellReference selectedCellReference = selectionManager.getSelectedCellReference(); if (selectedCellReference != null) { if (selectedCellReference.getRow() >= firstAffectedRow && selectedCellReference.getRow() <= lastAffectedRow) { selectionManager.onSheetAddressChanged(selectedCellReference.formatAsString(), false); } } }
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
/** * Gets the visibility state of the given row. A row is hidden when it has * zero height, see {@link Row#getZeroHeight()}. * //from w w w. j a va 2s. c o m * @param rowIndex * Index of the target row, 0-based * @return true if the target row is hidden, false if it is visible. */ public boolean isRowHidden(int rowIndex) { Row row = getActiveSheet().getRow(rowIndex); return row == null ? false : row.getZeroHeight(); }
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
/** * Sets the row height for currently active sheet. Updates both POI model * and the visible sheet./* ww w . j av a 2 s.c o m*/ * * @param index * Index of target row, 0-based * @param height * New row height in points */ public void setRowHeight(int index, float height) { if (height == 0.0F) { setRowHidden(index, true); } else { Row row = getActiveSheet().getRow(index); if (getState().hiddenRowIndexes.contains(Integer.valueOf(index + 1))) { getState().hiddenRowIndexes.remove(Integer.valueOf(index + 1)); if (row != null && row.getZeroHeight()) { row.setZeroHeight(false); } } getState().rowH[index] = height; if (row == null) { row = getActiveSheet().createRow(index); } row.setHeightInPoints(height); } }
From source file:com.vaadin.addon.spreadsheet.Spreadsheet.java
License:Open Source License
private void loadCellComments(int r1, int c1, int r2, int c2) { Sheet sheet = getActiveSheet();/*from w w w . ja v a2s . c o m*/ for (int r = r1 - 1; r < r2; r++) { Row row = sheet.getRow(r); if (row != null && row.getZeroHeight()) { continue; } for (int c = c1 - 1; c < c2; c++) { if (sheet.isColumnHidden(c)) { continue; } int c_one_based = c + 1; int row_one_based = r + 1; MergedRegion region = mergedRegionContainer.getMergedRegion(c_one_based, row_one_based); // do not add comments that are "below" merged regions. // client side handles cases where comment "moves" (because // shifting etc.) from merged cell into basic or vice versa. if (region == null || region.col1 == c_one_based && region.row1 == row_one_based) { Comment comment = sheet.getCellComment(r, c); String key = SpreadsheetUtil.toKey(c_one_based, row_one_based); if (comment != null) { // by default comments are shown when mouse is over the // red // triangle on the cell's top right corner. the comment // position is calculated so that it is completely // visible. getState().cellComments.put(key, comment.getString().getString()); getState().cellCommentAuthors.put(key, comment.getAuthor()); if (comment.isVisible()) { getState().visibleCellComments.add(key); } } if (isMarkedAsInvalidFormula(c_one_based, row_one_based)) { getState().invalidFormulaCells.add(key); } } else { c = region.col2 - 1; } } } }
From source file:com.vaadin.addon.spreadsheet.SpreadsheetFactory.java
License:Open Source License
/** * Calculate size-related values for the sheet. Includes row and column * counts, actual row heights and column widths, and hidden row and column * indexes.// w w w .j a va 2 s . c o m * * @param spreadsheet * @param sheet */ static void calculateSheetSizes(final Spreadsheet spreadsheet, final Sheet sheet) { // Always have at least the default amount of rows int rows = sheet.getLastRowNum() + 1; if (rows < spreadsheet.getDefaultRowCount()) { rows = spreadsheet.getDefaultRowCount(); } spreadsheet.getState().rows = rows; final float[] rowHeights = new float[rows]; int cols = 0; int tempRowIndex = -1; final ArrayList<Integer> hiddenRowIndexes = new ArrayList<Integer>(); for (Row row : sheet) { int rIndex = row.getRowNum(); // set the empty rows to have the default row width while (++tempRowIndex != rIndex) { rowHeights[tempRowIndex] = spreadsheet.getState().defRowH; } if (row.getZeroHeight()) { rowHeights[rIndex] = 0.0F; hiddenRowIndexes.add(rIndex + 1); } else { rowHeights[rIndex] = row.getHeightInPoints(); } int c = row.getLastCellNum(); if (c > cols) { cols = c; } } if (rows > sheet.getLastRowNum() + 1) { float defaultRowHeightInPoints = sheet.getDefaultRowHeightInPoints(); int lastRowNum = sheet.getLastRowNum(); // if sheet is empty, also set height for 'last row' (index // zero) if (lastRowNum == 0) { rowHeights[0] = defaultRowHeightInPoints; } // set default height for the rest for (int i = lastRowNum + 1; i < rows; i++) { rowHeights[i] = defaultRowHeightInPoints; } } spreadsheet.getState().hiddenRowIndexes = hiddenRowIndexes; spreadsheet.getState().rowH = rowHeights; // Always have at least the default amount of columns if (cols < spreadsheet.getDefaultColumnCount()) { cols = spreadsheet.getDefaultColumnCount(); } spreadsheet.getState().cols = cols; final int[] colWidths = new int[cols]; final ArrayList<Integer> hiddenColumnIndexes = new ArrayList<Integer>(); for (int i = 0; i < cols; i++) { if (sheet.isColumnHidden(i)) { colWidths[i] = 0; hiddenColumnIndexes.add(i + 1); } else { colWidths[i] = ExcelToHtmlUtils.getColumnWidthInPx(sheet.getColumnWidth(i)); } } spreadsheet.getState().hiddenColumnIndexes = hiddenColumnIndexes; spreadsheet.getState().colW = colWidths; }
From source file:mpqq.MPQQ.java
private static XSSFWorkbook procTab1(XSSFWorkbook referenceWB, XSSFWorkbook mpqqWB, int referenceFirstRow) { XSSFSheet trackerTab = referenceWB.getSheetAt(USE_FOR_TAB1); XSSFSheet tab1 = mpqqWB.getSheetAt(1); //Iterator<Row> rowIterator = trackerTab.iterator(); DataFormatter df = new DataFormatter(); //MPQQ first row int rowIdx = 11; for (int refCurRow = referenceFirstRow; refCurRow <= trackerTab.getLastRowNum(); refCurRow++) { Row row = trackerTab.getRow(refCurRow); //Check if row is visible if (!row.getZeroHeight() || (row.isFormatted() && row.getRowStyle().getHidden())) { int colIdx = 1; //Iterate trough the Columns Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getColumnIndex()) { case 3: Cell currentCell = checkRowCellExists(tab1, rowIdx, colIdx); currentCell.setCellValue(df.formatCellValue(row.getCell(T2PEPSICO_STOCK_CODE))); //Go to next Column colIdx++;// w w w . j ava2 s . c o m break; case 4: break; default: } } //Jump Next Row rowIdx++; } } return mpqqWB; }
From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java
License:Apache License
private static InnerRow getTemplateRow(Map<Integer, InnerRow> cache, Sheet sheet, ExcelWriteSheetProcessor<?> sheetProcessor, int rowIndex) { InnerRow cachedRow = cache.get(rowIndex); if (cachedRow != null || cache.containsKey(rowIndex)) { return cachedRow; }/*from ww w . j a va2 s .c o m*/ InnerRow templateRow = null; if (sheetProcessor.getTemplateStartRowIndex() != null && sheetProcessor.getTemplateEndRowIndex() != null) { if (rowIndex <= sheetProcessor.getTemplateEndRowIndex()) { return null; } int tempRowIndex = (rowIndex - sheetProcessor.getTemplateEndRowIndex() - 1) % (sheetProcessor.getTemplateEndRowIndex() - sheetProcessor.getTemplateStartRowIndex() + 1) + sheetProcessor.getTemplateStartRowIndex(); Row tempRow = sheet.getRow(tempRowIndex); if (tempRow != null) { templateRow = new InnerRow(); templateRow.setHeight(tempRow.getHeight()); templateRow.setHeightInPoints(tempRow.getHeightInPoints()); templateRow.setRowStyle(tempRow.getRowStyle()); templateRow.setZeroHeight(tempRow.getZeroHeight()); for (int i = tempRow.getFirstCellNum(); i <= tempRow.getLastCellNum(); i++) { Cell cell = tempRow.getCell(i); if (cell != null) { InnerCell innerCell = new InnerCell(); innerCell.setCellStyle(cell.getCellStyle()); innerCell.setCellType(cell.getCellType()); templateRow.setCell(i, innerCell); } } } } cache.put(rowIndex, templateRow); return templateRow; }