poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1294127 - in /poi/trunk: src/documentation/content/xdocs/status.xml src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java test-data/spreadsheet/51790.xlsx
Date Mon, 27 Feb 2012 12:18:46 GMT
Author: yegor
Date: Mon Feb 27 12:18:45 2012
New Revision: 1294127

URL: http://svn.apache.org/viewvc?rev=1294127&view=rev
Log:
Bugzilla 51790: fixed reading shared formulas in XSSF 

Added:
    poi/trunk/test-data/spreadsheet/51790.xlsx   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1294127&r1=1294126&r2=1294127&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Feb 27 12:18:45 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="add">51710 - fixed reading shared formulas
in XSSF </action>
            <action dev="poi-developers" type="add">52708 - misc improvements in CellFormat
</action>
            <action dev="poi-developers" type="add">52690 - added a getter for length
of encrypted data in Ecma and Agile decryptors</action>
            <action dev="poi-developers" type="fix">52255 - support adding TIFF,EPS
and WPG pictures in OOXML documents </action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1294127&r1=1294126&r2=1294127&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Mon Feb 27 12:18:45
2012
@@ -2670,7 +2670,20 @@ public class XSSFSheet extends POIXMLDoc
         if (f != null && f.getT() == STCellFormulaType.SHARED && f.isSetRef()
&& f.getStringValue() != null) {
             // save a detached  copy to avoid XmlValueDisconnectedException,
             // this may happen when the master cell of a shared formula is changed
-            sharedFormulas.put((int)f.getSi(), (CTCellFormula)f.copy());
+            CTCellFormula sf = (CTCellFormula)f.copy();
+            CellRangeAddress sfRef = CellRangeAddress.valueOf(sf.getRef());
+            CellReference cellRef = new CellReference(cell);
+            // If the shared formula range preceeds the master cell then the preseeing part
is discarded, e.g.
+            // if the cell is E60 and the shared formula range is C60:M85 then the effective
range is E60:M85
+            // see more details in https://issues.apache.org/bugzilla/show_bug.cgi?id=51710
+            if(cellRef.getCol() > sfRef.getFirstColumn() || cellRef.getRow() > sfRef.getFirstRow()){
+                String effectiveRef = new CellRangeAddress(
+                        Math.max(cellRef.getRow(), sfRef.getFirstRow()), sfRef.getLastRow(),
+                        Math.max(cellRef.getCol(), sfRef.getFirstColumn()), sfRef.getLastColumn()).formatAsString();
+                sf.setRef(effectiveRef);
+            }
+
+            sharedFormulas.put((int)f.getSi(), sf);
         }
         if (f != null && f.getT() == STCellFormulaType.ARRAY && f.getRef()
!= null) {
             arrayFormulas.add(CellRangeAddress.valueOf(f.getRef()));

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1294127&r1=1294126&r2=1294127&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Mon Feb
27 12:18:45 2012
@@ -44,6 +44,7 @@ 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.AreaReference;
+import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.CalculationChain;
@@ -1285,4 +1286,35 @@ public final class TestXSSFBugs extends 
        assertEquals(20.0, c1.getNumericCellValue());
        assertEquals(20.0, c2.getNumericCellValue());
     }
+
+    /**
+     * Bugzilla 51710: problems reading shared formuals from .xlsx
+     */
+    public void test51710() {
+        Workbook wb = XSSFTestDataSamples.openSampleWorkbook("51790.xlsx");
+
+        final String[] columns = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N"};
+        final int rowMax = 500; // bug triggers on row index 59
+
+        Sheet sheet = wb.getSheetAt(0);
+
+
+        // go through all formula cells
+        for (int rInd = 2; rInd <= rowMax; rInd++) {
+            Row row = sheet.getRow(rInd);
+
+            for (int cInd = 1; cInd <= 12; cInd++) {
+                Cell cell = row.getCell(cInd);
+                String formula = cell.getCellFormula();
+                CellReference ref = new CellReference(cell);
+
+                //simulate correct answer
+                String correct = "$A" + (rInd + 1) + "*" + columns[cInd] + "$2";
+
+                assertEquals("Incorrect formula in " + ref.formatAsString(), correct, formula);
+            }
+
+        }
+    }
+
 }

Added: poi/trunk/test-data/spreadsheet/51790.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/51790.xlsx?rev=1294127&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/51790.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/vnd.ms-excel



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


Mime
View raw message