use of org.apache.poi.ss.SpreadsheetVersion in project poi by apache.
the class BaseTestSheet method createRowAfterLastRow.
@Test(expected = IllegalArgumentException.class)
public void createRowAfterLastRow() throws IOException {
final SpreadsheetVersion version = _testDataProvider.getSpreadsheetVersion();
final Workbook workbook = _testDataProvider.createWorkbook();
final Sheet sh = workbook.createSheet();
sh.createRow(version.getLastRowIndex());
try {
// Row number must be between 0 and last row
sh.createRow(version.getLastRowIndex() + 1);
} finally {
workbook.close();
}
}
use of org.apache.poi.ss.SpreadsheetVersion in project poi by apache.
the class TestCellReference method isColWithinRange.
@Test
public void isColWithinRange() {
SpreadsheetVersion ss = SpreadsheetVersion.EXCEL2007;
assertTrue("(empty)", CellReference.isColumnWithinRange("", ss));
assertTrue("first column (A)", CellReference.isColumnWithinRange("A", ss));
assertTrue("last column (XFD)", CellReference.isColumnWithinRange("XFD", ss));
assertFalse("1 beyond last column (XFE)", CellReference.isColumnWithinRange("XFE", ss));
}
use of org.apache.poi.ss.SpreadsheetVersion in project poi by apache.
the class WorkbookEvaluator method adjustRegionRelativeReference.
/**
* Adjust the formula relative cell references by a given delta
* @param ptgs
* @param deltaRow target row offset from the top left cell of a region
* @param deltaColumn target column offset from the top left cell of a region
* @return true if any Ptg references were shifted
* @throws IndexOutOfBoundsException if the resulting shifted row/column indexes are over the document format limits
* @throws IllegalArgumentException if either of the deltas are negative, as the assumption is we are shifting formulas
* relative to the top left cell of a region.
*/
protected boolean adjustRegionRelativeReference(Ptg[] ptgs, int deltaRow, int deltaColumn) {
if (deltaRow < 0)
throw new IllegalArgumentException("offset row must be positive");
if (deltaColumn < 0)
throw new IllegalArgumentException("offset column must be positive");
boolean shifted = false;
for (Ptg ptg : ptgs) {
// base class for cell reference "things"
if (ptg instanceof RefPtgBase) {
RefPtgBase ref = (RefPtgBase) ptg;
// re-calculate cell references
final SpreadsheetVersion version = _workbook.getSpreadsheetVersion();
if (ref.isRowRelative()) {
final int rowIndex = ref.getRow() + deltaRow;
if (rowIndex > version.getMaxRows()) {
throw new IndexOutOfBoundsException(version.name() + " files can only have " + version.getMaxRows() + " rows, but row " + rowIndex + " was requested.");
}
ref.setRow(rowIndex);
shifted = true;
}
if (ref.isColRelative()) {
final int colIndex = ref.getColumn() + deltaColumn;
if (colIndex > version.getMaxColumns()) {
throw new IndexOutOfBoundsException(version.name() + " files can only have " + version.getMaxColumns() + " columns, but column " + colIndex + " was requested.");
}
ref.setColumn(colIndex);
shifted = true;
}
}
}
return shifted;
}
use of org.apache.poi.ss.SpreadsheetVersion in project poi by apache.
the class XSSFCell method checkBounds.
/**
* @throws RuntimeException if the bounds are exceeded.
*/
private static void checkBounds(int cellIndex) {
SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007;
int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
if (cellIndex < 0 || cellIndex > maxcol) {
throw new IllegalArgumentException("Invalid column index (" + cellIndex + "). Allowable column range for " + v.name() + " is (0.." + maxcol + ") or ('A'..'" + v.getLastColumnName() + "')");
}
}
use of org.apache.poi.ss.SpreadsheetVersion in project poi by apache.
the class BaseTestBugzillaIssues method bug46729_testMaxFunctionArguments.
@Test
public void bug46729_testMaxFunctionArguments() throws IOException {
String[] func = { "COUNT", "AVERAGE", "MAX", "MIN", "OR", "SUBTOTAL", "SKEW" };
SpreadsheetVersion ssVersion = _testDataProvider.getSpreadsheetVersion();
Workbook wb = _testDataProvider.createWorkbook();
Cell cell = wb.createSheet().createRow(0).createCell(0);
String fmla;
for (String name : func) {
fmla = createFunction(name, 5);
cell.setCellFormula(fmla);
fmla = createFunction(name, ssVersion.getMaxFunctionArgs());
cell.setCellFormula(fmla);
try {
fmla = createFunction(name, ssVersion.getMaxFunctionArgs() + 1);
cell.setCellFormula(fmla);
fail("Expected FormulaParseException");
} catch (RuntimeException e) {
assertTrue(e.getMessage().startsWith("Too many arguments to function '" + name + "'"));
}
}
wb.close();
}
Aggregations