https://svn.apache.org:443/repos/asf/poi/trunk
........
r675783 | nick | 2008-07-10 23:14:25 +0100 (Thu, 10 Jul 2008) | 1 line
Add disabled test for bug #45376
........
r675785 | nick | 2008-07-10 23:22:24 +0100 (Thu, 10 Jul 2008) | 1 line
Tweak test to run forward and back
........
r675792 | nick | 2008-07-10 23:39:53 +0100 (Thu, 10 Jul 2008) | 1 line
Improve javadocs relating to getLastRowNumber
........
r675793 | nick | 2008-07-10 23:43:01 +0100 (Thu, 10 Jul 2008) | 1 line
Add a test to show that the behaviour around bug #30635 is exactly as you would expect, and the bug report is invalid
........
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@675795
13f79535-47bb-0310-9956-
ffa450edef68
}
/**
- * 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()
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());
+ }
}
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<timings.length; i++) {
+ avg += timings[i];
+ }
+ avg = (long)( ((double)avg) / timings.length );
+
+ // Warn if any took more then 1.5 the average
+ // TODO - replace with assert or similar
+ for(int i=0; i<timings.length; i++) {
+ if(timings[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