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
This commit is contained in:
Yegor Kozlov 2009-08-05 17:54:56 +00:00
parent 30ac3a9d07
commit d5f241bfb8
3 changed files with 36 additions and 9 deletions

View File

@ -33,6 +33,7 @@
<changes> <changes>
<release version="3.5-beta7" date="2009-??-??"> <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">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">47598 - Improved formula evaluator number comparison</action>
<action dev="POI-DEVELOPERS" type="fix">47571 - Fixed XWPFWordExtractor to extract inserted/deleted text</action> <action dev="POI-DEVELOPERS" type="fix">47571 - Fixed XWPFWordExtractor to extract inserted/deleted text</action>

View File

@ -937,17 +937,18 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
boolean removingRange = startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1; boolean removingRange = startColumn == -1 && endColumn == -1 && startRow == -1 && endRow == -1;
XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex); XSSFName name = getBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
if (removingRange && name != null) { if (removingRange) {
namedRanges.remove(name); if(name != null)namedRanges.remove(name);
return; return;
} }
if (name == null) { if (name == null) {
name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex); name = createBuiltInName(XSSFName.BUILTIN_PRINT_TITLE, sheetIndex);
String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
name.setRefersToFormula(reference);
namedRanges.add(name); namedRanges.add(name);
} }
String reference = getReferenceBuiltInRecord(name.getSheetName(), startColumn, endColumn, startRow, endRow);
name.setRefersToFormula(reference);
XSSFPrintSetup printSetup = sheet.getPrintSetup(); XSSFPrintSetup printSetup = sheet.getPrintSetup();
printSetup.setValidSettings(false); printSetup.setValidSettings(false);
} }
@ -959,17 +960,26 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
String escapedName = SheetNameFormatter.format(sheetName); 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 rowRef = new CellReference(sheetName, startR, 0, true, true);
CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true); CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
String r = ""; String r = "";
if(startR == -1 && endR == -1) r = "";
else {
if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) { if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) {
r = "," + escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1]; 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) { private static String getReferencePrintArea(String sheetName, int startC, int endC, int startR, int endR) {

View File

@ -39,6 +39,8 @@ public final class TestXSSFName extends BaseTestNamedRange {
XSSFWorkbook wb = getTestDataProvider().createWorkbook(); XSSFWorkbook wb = getTestDataProvider().createWorkbook();
XSSFSheet sheet = wb.createSheet("First Sheet"); XSSFSheet sheet = wb.createSheet("First Sheet");
wb.setRepeatingRowsAndColumns(0, -1, -1, -1, -1);
// set repeating rows and columns twice for the first sheet // set repeating rows and columns twice for the first sheet
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
wb.setRepeatingRowsAndColumns(0, 0, 0, 0, 3); 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(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula()); 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 // Save and re-open
XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb); XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);