]> source.dussan.org Git - poi.git/commitdiff
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-63924...
authorNick Burch <nick@apache.org>
Thu, 10 Jul 2008 22:57:13 +0000 (22:57 +0000)
committerNick Burch <nick@apache.org>
Thu, 10 Jul 2008 22:57:13 +0000 (22:57 +0000)
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

src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/testcases/org/apache/poi/hssf/data/45376.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java

index dc18e5599e50af0e6f21efa04d97451253de1fcd..2e93d461298120b146733a856dc1e8a4ab0df3a9 100644 (file)
@@ -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 (file)
index 0000000..74602fd
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/45376.xls differ
index bfd3593180a3aba8753597129b6bd059ab3e0252..45671484a9478dce3cfea5b2fcc049ef8cf8b91e 100644 (file)
@@ -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());
+    }
 }
index 349cfa8a8504b4d4cb7910eae054b3a6dc11f2f1..318fcd2bf6262923c0ae0c58f24ab0d9c4364809 100644 (file)
@@ -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<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