diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index dc18e5599..2e93d4612 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -365,18 +365,25 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet } /** - * gets the first row on the sheet - * @return the number of the first logical row on the sheet + * Gets the first row on the sheet + * @return the number of the first logical row on the sheet, zero based */ - public int getFirstRowNum() { return firstrow; } /** - * gets the last row on the sheet - * @return last row contained n this sheet. + * Gets the number last row on the sheet. + * Owing to idiosyncrasies in the excel file + * format, if the result of calling this method + * is zero, you can't tell if that means there + * are zero rows on the sheet, or one at + * position zero. For that case, additionally + * call {@link #getPhysicalNumberOfRows()} to + * tell if there is a row at position zero + * or not. + * @return the number of the last row contained in this sheet, zero based. */ public int getLastRowNum() diff --git a/src/testcases/org/apache/poi/hssf/data/45376.xls b/src/testcases/org/apache/poi/hssf/data/45376.xls new file mode 100644 index 000000000..74602fd0b Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45376.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index bfd359318..45671484a 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1273,4 +1273,53 @@ public final class TestBugs extends TestCase { assertEquals("{=sin(B1:B9){9,1)[1][0]", nc2.getCellFormula()); assertEquals("{=sin(B1:B9){9,1)[2][0]", nc3.getCellFormula()); } + + /** + * People are all getting confused about the last + * row and cell number + */ + public void test30635() throws Exception { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet(); + + // No rows, everything is 0 + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + assertEquals(0, s.getPhysicalNumberOfRows()); + + // One row, most things are 0, physical is 1 + s.createRow(0); + assertEquals(0, s.getFirstRowNum()); + assertEquals(0, s.getLastRowNum()); + assertEquals(1, s.getPhysicalNumberOfRows()); + + // And another, things change + s.createRow(4); + assertEquals(0, s.getFirstRowNum()); + assertEquals(4, s.getLastRowNum()); + assertEquals(2, s.getPhysicalNumberOfRows()); + + + // Now start on cells + HSSFRow r = s.getRow(0); + assertEquals(-1, r.getFirstCellNum()); + assertEquals(-1, r.getLastCellNum()); + assertEquals(0, r.getPhysicalNumberOfCells()); + + // Add a cell, things move off -1 + r.createCell((short)0); + assertEquals(0, r.getFirstCellNum()); + assertEquals(1, r.getLastCellNum()); // last cell # + 1 + assertEquals(1, r.getPhysicalNumberOfCells()); + + r.createCell((short)1); + assertEquals(0, r.getFirstCellNum()); + assertEquals(2, r.getLastCellNum()); // last cell # + 1 + assertEquals(2, r.getPhysicalNumberOfCells()); + + r.createCell((short)4); + assertEquals(0, r.getFirstCellNum()); + assertEquals(5, r.getLastCellNum()); // last cell # + 1 + assertEquals(3, r.getPhysicalNumberOfCells()); + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java index 349cfa8a8..318fcd2bf 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java @@ -294,4 +294,70 @@ public final class TestFormulaEvaluatorBugs extends TestCase { throw e; } } + + /** + * Apparently, each subsequent call takes longer, which is very + * odd. + * We think it's because the formulas are recursive and crazy + */ + public void DISABLEDtestSlowEvaluate45376() throws Exception { + HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("45376.xls"); + + final String SHEET_NAME = "Eingabe"; + final int row = 6; + final HSSFSheet sheet = wb.getSheet(SHEET_NAME); + + int firstCol = 4; + int lastCol = 14; + long[] timings = new long[lastCol-firstCol+1]; + long[] rtimings = new long[lastCol-firstCol+1]; + + long then, now; + + final HSSFRow excelRow = sheet.getRow(row); + for(int i = firstCol; i <= lastCol; i++) { + final HSSFCell excelCell = excelRow.getCell(i); + final HSSFFormulaEvaluator evaluator = new + HSSFFormulaEvaluator(sheet, wb); + + evaluator.setCurrentRow(excelRow); + + now = System.currentTimeMillis(); + evaluator.evaluate(excelCell); + then = System.currentTimeMillis(); + timings[i-firstCol] = (then-now); + System.err.println("Col " + i + " took " + (then-now) + "ms"); + } + for(int i = lastCol; i >= firstCol; i--) { + final HSSFCell excelCell = excelRow.getCell(i); + final HSSFFormulaEvaluator evaluator = new + HSSFFormulaEvaluator(sheet, wb); + + evaluator.setCurrentRow(excelRow); + + now = System.currentTimeMillis(); + evaluator.evaluate(excelCell); + then = System.currentTimeMillis(); + rtimings[i-firstCol] = (then-now); + System.err.println("Col " + i + " took " + (then-now) + "ms"); + } + + // The timings for each should be about the same + long avg = 0; + for(int i=0; i 1.5*avg) { + System.err.println("Doing col " + (i+firstCol) + + " took " + timings[i] + "ms, vs avg " + + avg + "ms" + ); + } + } + } } \ No newline at end of file