poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1819770 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/streaming/SXSSFSheet.java testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
Date Mon, 01 Jan 2018 14:39:15 GMT
Author: centic
Date: Mon Jan  1 14:39:15 2018
New Revision: 1819770

URL: http://svn.apache.org/viewvc?rev=1819770&view=rev
Log:
Bug 61648: Test Sheet.setArrayFormula for SXSSF

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1819770&r1=1819769&r2=1819770&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Mon Jan  1 14:39:15
2018
@@ -970,8 +970,7 @@ public class SXSSFSheet implements Sheet
      */
     @NotImplemented
     @Override
-    public void shiftRows(int startRow, int endRow, int n)
-    {
+    public void shiftRows(int startRow, int endRow, int n) {
         throw new RuntimeException("NotImplemented");
     }
 
@@ -1730,9 +1729,12 @@ public class SXSSFSheet implements Sheet
      * @return the {@link CellRange} of cells affected by this change
      */
     @Override
-    public CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress
range)
-    {
-        return _sh.setArrayFormula(formula, range);
+    public CellRange<? extends Cell> setArrayFormula(String formula, CellRangeAddress
range) {
+        // the simple approach via _sh does not work as it creates rows in the XSSFSheet
and thus causes
+        // corrupted .xlsx files as rows appear multiple times in the resulting sheetX.xml
files
+        // return _sh.setArrayFormula(formula, range);
+
+        throw new RuntimeException("NotImplemented");
     }
 
     /**
@@ -1742,9 +1744,12 @@ public class SXSSFSheet implements Sheet
      * @return the {@link CellRange} of cells affected by this change
      */
     @Override
-    public CellRange<? extends Cell> removeArrayFormula(Cell cell)
-    {
-        return _sh.removeArrayFormula(cell);
+    public CellRange<? extends Cell> removeArrayFormula(Cell cell) {
+        // the simple approach via _sh does not work as it creates rows in the XSSFSheet
and thus causes
+        // corrupted .xlsx files as rows appear multiple times in the resulting sheetX.xml
files
+        // return _sh.removeArrayFormula(cell);
+
+        throw new RuntimeException("NotImplemented");
     }
     
     @Override

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java?rev=1819770&r1=1819769&r2=1819770&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java Mon Jan
 1 14:39:15 2018
@@ -18,15 +18,22 @@
 package org.apache.poi.xssf.usermodel;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
 
+import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.PrintSetup;
+import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -99,4 +106,64 @@ public final class TestSXSSFBugs extends
             }
         }
     }
+
+    @Test
+    public void bug61648() throws Exception {
+        // works as expected
+        writeWorkbook(new XSSFWorkbook(), "/tmp/61648.xlsx", XSSFITestDataProvider.instance);
+
+        // does not work
+        try {
+            writeWorkbook(new SXSSFWorkbook(), "/tmp/61648s.xlsx", SXSSFITestDataProvider.instance);
+            fail("Should catch exception here");
+        } catch (RuntimeException e) {
+            // this is not implemented yet
+        }
+    }
+
+    void writeWorkbook(Workbook wb, String filename, ITestDataProvider testDataProvider)
throws IOException {
+        Sheet sheet = wb.createSheet("array formula test");
+
+        int rowIndex = 0;
+        int colIndex = 0;
+        Row row = sheet.createRow(rowIndex++);
+
+        Cell cell = row.createCell(colIndex++);
+        cell.setCellType(CellType.STRING);
+        cell.setCellValue("multiple");
+        cell = row.createCell(colIndex++);
+        cell.setCellType(CellType.STRING);
+        cell.setCellValue("unique");
+
+        writeRow(sheet, rowIndex++, 80d, "INDEX(A2:A7, MATCH(FALSE, ISBLANK(A2:A7), 0))");
+        writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B2, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
+        writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B3, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
+        writeRow(sheet, rowIndex++, 2d,  "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B4, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
+        writeRow(sheet, rowIndex++, 30d, "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B5, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
+        writeRow(sheet, rowIndex++, 2d,  "IFERROR(INDEX(A2:A7, MATCH(1, (COUNTIF(B2:B6, A2:A7)
= 0) * (NOT(ISBLANK(A2:A7))), 0)), \"\")");
+
+        /*FileOutputStream fileOut = new FileOutputStream(filename);
+        wb.write(fileOut);
+        fileOut.close();*/
+
+        Workbook wbBack = testDataProvider.writeOutAndReadBack(wb);
+        assertNotNull(wbBack);
+        wbBack.close();
+
+        wb.close();
+    }
+
+    void writeRow(Sheet sheet, int rowIndex, Double col0Value, String col1Value) {
+        int colIndex = 0;
+        Row row = sheet.createRow(rowIndex);
+
+        // numeric value cell
+        Cell cell = row.createCell(colIndex++);
+        cell.setCellType(CellType.NUMERIC);
+        cell.setCellValue(col0Value);
+
+        // formula value cell
+        CellRangeAddress range = new CellRangeAddress(rowIndex, rowIndex, colIndex, colIndex);
+        sheet.setArrayFormula(col1Value, range);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message