/** * Remove a row from this sheet. All cells contained in the row are removed as well * * @param row representing a row to remove. */ @Override public void removeRow(Row row) { if (row.getSheet() != this) { throw new IllegalArgumentException("Specified row does not belong to this sheet"); } for(Iterator<Map.Entry<Integer, SXSSFRow>> iter = _rows.entrySet().iterator(); iter.hasNext();) { Map.Entry<Integer, SXSSFRow> entry = iter.next(); if(entry.getValue() == row) { iter.remove(); return; } } }
/** * Return the cell's style. * * @return the cell's style. Always not-null. Default cell style has zero index and can be obtained as * <code>workbook.getCellStyleAt(0)</code> * @see org.apache.poi.ss.usermodel.Workbook#getCellStyleAt(int) */ @Override public CellStyle getCellStyle() { if(_style == null){ SXSSFWorkbook wb = (SXSSFWorkbook)getRow().getSheet().getWorkbook(); return wb.getCellStyleAt(0); } else { return _style; } }
if (row.getSheet() != this) { throw new IllegalArgumentException("Specified row does not belong to this sheet");
/** * Looks for text in the cell that should be unicode, like α and provides the * unicode version of it. * *@param cell The cell to check for unicode values *@return translated to unicode */ public static Cell translateUnicodeValues(Cell cell) { String s = cell.getRichStringCellValue().getString(); boolean foundUnicode = false; String lowerCaseStr = s.toLowerCase(Locale.ROOT); for (UnicodeMapping entry : unicodeMappings) { String key = entry.entityName; if (lowerCaseStr.contains(key)) { s = s.replaceAll(key, entry.resolvedValue); foundUnicode = true; } } if (foundUnicode) { cell.setCellValue(cell.getRow().getSheet().getWorkbook().getCreationHelper() .createRichTextString(s)); } return cell; }
} else if (srcStartRow.getSheet().getWorkbook() != curRow.getSheet().getWorkbook()) { throw new IllegalArgumentException("All rows in srcRows must belong to the same sheet in the same workbook. " + "Expected all rows from same workbook (" + srcStartRow.getSheet().getWorkbook() + "). " + "Got srcRows[" + index + "] from different workbook (" + curRow.getSheet().getWorkbook() + ")."); } else if (srcStartRow.getSheet() != curRow.getSheet()) { throw new IllegalArgumentException("All rows in srcRows must belong to the same sheet. " + "Expected all rows from " + srcStartRow.getSheet().getSheetName() + ". " + "Got srcRows[" + index + "] from " + curRow.getSheet().getSheetName()); for (CellRangeAddress srcRegion : srcStartRow.getSheet().getMergedRegions()) { if (srcStartRowNum <= srcRegion.getFirstRow() && srcRegion.getLastRow() <= srcEndRowNum) {
/** * Creates a cell, gives it a value, and applies a style if provided * * @param row the row to create the cell in * @param column the column index to create the cell in * @param value The value of the cell * @param style If the style is not null, then set * @return A new Cell */ public static Cell createCell(Row row, int column, String value, CellStyle style) { Cell cell = getCell(row, column); cell.setCellValue(cell.getRow().getSheet().getWorkbook().getCreationHelper() .createRichTextString(value)); if (style != null) { cell.setCellStyle(style); } return cell; }
public void removeRow(Row row) { HSSFRow hrow = (HSSFRow) row; if (row.getSheet() != this) { throw new IllegalArgumentException("Specified row does not belong to this sheet");
/** * Shift a formula using the supplied FormulaShifter * * @param row the row of the cell this formula belongs to. Used to get a reference to the parent workbook. * @param formula the formula to shift * @param formulaShifter the FormulaShifter object that operates on the parsed formula tokens * @return the shifted formula if the formula was changed, * <code>null</code> if the formula wasn't modified */ /*package*/ static String shiftFormula(Row row, String formula, FormulaShifter formulaShifter) { Sheet sheet = row.getSheet(); Workbook wb = sheet.getWorkbook(); int sheetIndex = wb.getSheetIndex(sheet); final int rowIndex = row.getRowNum(); XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create((XSSFWorkbook) wb); try { Ptg[] ptgs = FormulaParser.parse(formula, fpb, FormulaType.CELL, sheetIndex, rowIndex); String shiftedFmla = null; if (formulaShifter.adjustFormula(ptgs, sheetIndex)) { shiftedFmla = FormulaRenderer.toFormulaString(fpb, ptgs); } return shiftedFmla; } catch (FormulaParseException fpe) { // Log, but don't change, rather than breaking logger.log(POILogger.WARN, "Error shifting formula on row ", row.getRowNum(), fpe); return formula; } }
for (CellRangeAddress srcRegion : srcRow.getSheet().getMergedRegions()) { if (srcRowNum == srcRegion.getFirstRow() && srcRowNum == srcRegion.getLastRow()) { CellRangeAddress destRegion = srcRegion.copy();
private static List<Matcher<Row>> createCellMatchers(Row row) { List<Matcher<Row>> matchers = new ArrayList<Matcher<Row>>(); for (Cell expected : row) matchers.add(hasSameCell(row.getSheet(), expected)); return matchers; }
@Override public void describeTo(Description description) { description.appendText("row ").appendValue(asExcelRow(expected)).appendText(" to be present") .appendText(" in sheet ").appendValue(expected.getSheet().getSheetName()); } }
@Override protected boolean matchesSafely(Row actual, Description mismatch) { if (actual == null) { mismatch.appendText("row ").appendValue(asExcelRow(expected)).appendText(" is missing") .appendText(" in sheet ").appendValue(expected.getSheet().getSheetName()); return false; } return true; }
@Override public void describeTo(Description description) { description.appendValue(numberOfCellsIn(expected)).appendText(" cell(s) on row ").appendValue(asExcelRow(expected)) .appendText(" sheet ").appendValue(expected.getSheet().getSheetName()); }
public Object readErrorCell(Cell cell) { if (isStrict()) { throw new ExcelReadException("Error cell value encountered: %s@[%s]", cell.getAddress(), cell.getRow().getSheet().getSheetName()); } return null; }
public Object readUnknownCellType(Cell cell) { if (isStrict()) { throw new ExcelReadException("Unknown cell type encountered: %s@[%s]", cell.getAddress(), cell.getRow().getSheet().getSheetName()); } return null; }
public Object readUnknownCellType(Cell cell) { if (isStrict()) { throw new ExcelReadException("Unknown cell type encountered: %s@[%s]", cell.getAddress(), cell.getRow().getSheet().getSheetName()); } return null; }
public Object readErrorCell(Cell cell) { if (isStrict()) { throw new ExcelReadException("Error cell value encountered: %s@[%s]", cell.getAddress(), cell.getRow().getSheet().getSheetName()); } return null; }
@Override public Cell attachTo(final Row row) { final Cell cell = this.origin.attachTo(row); cell.setCellStyle(row.getSheet().getWorkbook().createCellStyle()); for (final Style style : this.styles) { style.attachTo(cell); } return cell; }
public void errorSettingCellValueToPojo(Exception e, Cell cell, Object value, Class<?> schema) { String errorMessage = S.fmt("failed to set cell value[%s] to POJO[%s]: %s@[%s]", value, schema, cell.getAddress(), cell.getRow().getSheet().getSheetName()); if (isStrict()) { throw new ExcelReadException(e, errorMessage); } LOGGER.warn(e, errorMessage); } }
public void errorSettingCellValueToPojo(Exception e, Cell cell, Object value, Class<?> schema) { String errorMessage = S.fmt("failed to set cell value[%s] to POJO[%s]: %s@[%s]", value, schema, cell.getAddress(), cell.getRow().getSheet().getSheetName()); if (isStrict()) { throw new ExcelReadException(e, errorMessage); } LOGGER.warn(e, errorMessage); } }