diff options
author | Yegor Kozlov <yegor@apache.org> | 2009-08-05 17:54:56 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2009-08-05 17:54:56 +0000 |
commit | 02268557290830bff1c6dc7202600811e157dfad (patch) | |
tree | d7975c070c4c090b019dd6fa3f0ce6c68ae0babe /src | |
parent | df16f03172c33968ef96d2d6f484ace61460719a (diff) | |
download | poi-02268557290830bff1c6dc7202600811e157dfad.tar.gz poi-02268557290830bff1c6dc7202600811e157dfad.zip |
Avoid FormulaParseException in XSSFWorkbook.setRepeatingRowsAndColumns when removing repeated rows and columns, see Bugzilla 47620
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@801339 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
3 files changed, 36 insertions, 9 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index af0d90c143..e38256b67f 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ <changes> <release version="3.5-beta7" date="2009-??-??"> + <action dev="POI-DEVELOPERS" type="fix">47620 - Avoid FormulaParseException in XSSFWorkbook.setRepeatingRowsAndColumns when removing repeated rows and columns</action> <action dev="POI-DEVELOPERS" type="fix">47606 - Fixed XSSFCell to correctly parse column indexes greater than 702 (ZZ)</action> <action dev="POI-DEVELOPERS" type="fix">47598 - Improved formula evaluator number comparison</action> <action dev="POI-DEVELOPERS" type="fix">47571 - Fixed XWPFWordExtractor to extract inserted/deleted text</action> diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index e3961a51d8..d08cbc5eea 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -937,17 +937,18 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X boolean removingRange = startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1; XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex); - if (removingRange && name != null) { - namedRanges.remove(name); + if (removingRange) { + if(name != null)namedRanges.remove(name); return; } if (name == null) { name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex); - String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow); - name.setRefersToFormula(reference); namedRanges.add(name); } + String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow); + name.setRefersToFormula(reference); + XSSFPrintSetup printSetup = sheet.getPrintSetup(); printSetup.setValidSettings(false); } @@ -959,17 +960,26 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X String escapedName = SheetNameFormatter.format(sheetName); - String c = escapedName + "!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2]; + String c; + if(startC == -1 && endC == -1) c= ""; + else c = escapedName + "!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2]; CellReference rowRef = new CellReference(sheetName, startR, 0, true, true); CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true); String r = ""; - - if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) { - r = "," + escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1]; + if(startR == -1 && endR == -1) r = ""; + else { + if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) { + r = escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1]; + } } - return c + r; + + StringBuffer rng = new StringBuffer(); + rng.append(c); + if(rng.length() > 0 && r.length() > 0) rng.append(','); + rng.append(r); + return rng.toString(); } private static String getReferencePrintArea(String sheetName, int startC, int endC, int startR, int endR) { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java index 14bfdc790b..f2e8ecddc8 100755 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java @@ -39,6 +39,8 @@ public final class TestXSSFName extends BaseTestNamedRange { XSSFWorkbook wb = getTestDataProvider().createWorkbook(); XSSFSheet sheet = wb.createSheet("First Sheet"); + wb.setRepeatingRowsAndColumns(0, -1, -1, -1, -1); + // set repeating rows and columns twice for the first sheet for (int i = 0; i < 2; i++) { wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3); @@ -50,6 +52,20 @@ public final class TestXSSFName extends BaseTestNamedRange { assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName()); assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula()); + //remove the columns part + wb.setRepeatingRowsAndColumns(0, -1, -1, 0, 3); + assertEquals("'First Sheet'!$1:$4", nr1.getRefersToFormula()); + + //revert + wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3); + + //remove the rows part + wb.setRepeatingRowsAndColumns(0, 0, 0, -1, -1); + assertEquals("'First Sheet'!$A:$A", nr1.getRefersToFormula()); + + //revert + wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3); + // Save and re-open XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb); |