XSSF Pxgs must escape sheet names where required when generating the formula string
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1612150 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
44a6aef699
commit
a550397ac2
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.ptg;
|
package org.apache.poi.ss.formula.ptg;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.util.AreaReference;
|
import org.apache.poi.ss.util.AreaReference;
|
||||||
import org.apache.poi.util.LittleEndianOutput;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ public final class Area3DPxg extends AreaPtgBase implements Pxg {
|
|||||||
sb.append(externalWorkbookNumber);
|
sb.append(externalWorkbookNumber);
|
||||||
sb.append(']');
|
sb.append(']');
|
||||||
}
|
}
|
||||||
sb.append(sheetName);
|
SheetNameFormatter.appendFormat(sb, sheetName);
|
||||||
sb.append('!');
|
sb.append('!');
|
||||||
sb.append(formatReferenceAsString());
|
sb.append(formatReferenceAsString());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.ptg;
|
package org.apache.poi.ss.formula.ptg;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.usermodel.ErrorConstants;
|
import org.apache.poi.ss.usermodel.ErrorConstants;
|
||||||
import org.apache.poi.util.LittleEndianOutput;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
|
||||||
@ -71,7 +72,7 @@ public final class Deleted3DPxg extends OperandPtg implements Pxg {
|
|||||||
sb.append(']');
|
sb.append(']');
|
||||||
}
|
}
|
||||||
if (sheetName != null) {
|
if (sheetName != null) {
|
||||||
sb.append(sheetName);
|
SheetNameFormatter.appendFormat(sb, sheetName);
|
||||||
}
|
}
|
||||||
sb.append('!');
|
sb.append('!');
|
||||||
sb.append(ErrorConstants.getText(ErrorConstants.ERROR_REF));
|
sb.append(ErrorConstants.getText(ErrorConstants.ERROR_REF));
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.ptg;
|
package org.apache.poi.ss.formula.ptg;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.util.LittleEndianOutput;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,7 +80,7 @@ public final class NameXPxg extends OperandPtg implements Pxg {
|
|||||||
sb.append(']');
|
sb.append(']');
|
||||||
}
|
}
|
||||||
if (sheetName != null) {
|
if (sheetName != null) {
|
||||||
sb.append(sheetName);
|
SheetNameFormatter.appendFormat(sb, sheetName);
|
||||||
}
|
}
|
||||||
sb.append('!');
|
sb.append('!');
|
||||||
sb.append(nameName);
|
sb.append(nameName);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package org.apache.poi.ss.formula.ptg;
|
package org.apache.poi.ss.formula.ptg;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.formula.SheetNameFormatter;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
import org.apache.poi.util.LittleEndianOutput;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
|
||||||
@ -86,7 +87,9 @@ public final class Ref3DPxg extends RefPtgBase implements Pxg {
|
|||||||
sb.append(externalWorkbookNumber);
|
sb.append(externalWorkbookNumber);
|
||||||
sb.append(']');
|
sb.append(']');
|
||||||
}
|
}
|
||||||
sb.append(sheetName);
|
if (sheetName != null) {
|
||||||
|
SheetNameFormatter.appendFormat(sb, sheetName);
|
||||||
|
}
|
||||||
sb.append('!');
|
sb.append('!');
|
||||||
sb.append(formatReferenceAsString());
|
sb.append(formatReferenceAsString());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
|
@ -130,6 +130,15 @@ public final class TestXSSFFormulaParser {
|
|||||||
assertEquals("A1", ((Ref3DPxg)ptgs[0]).format2DRefAsString());
|
assertEquals("A1", ((Ref3DPxg)ptgs[0]).format2DRefAsString());
|
||||||
assertEquals("Uses!A1", ((Ref3DPxg)ptgs[0]).toFormulaString());
|
assertEquals("Uses!A1", ((Ref3DPxg)ptgs[0]).toFormulaString());
|
||||||
|
|
||||||
|
// Reference to a single cell in a different sheet, which needs quoting
|
||||||
|
ptgs = parse(fpb, "'Testing 47100'!A1");
|
||||||
|
assertEquals(1, ptgs.length);
|
||||||
|
assertEquals(Ref3DPxg.class, ptgs[0].getClass());
|
||||||
|
assertEquals(-1, ((Ref3DPxg)ptgs[0]).getExternalWorkbookNumber());
|
||||||
|
assertEquals("Testing 47100", ((Ref3DPxg)ptgs[0]).getSheetName());
|
||||||
|
assertEquals("A1", ((Ref3DPxg)ptgs[0]).format2DRefAsString());
|
||||||
|
assertEquals("'Testing 47100'!A1", ((Ref3DPxg)ptgs[0]).toFormulaString());
|
||||||
|
|
||||||
// Reference to a sheet scoped named range from another sheet
|
// Reference to a sheet scoped named range from another sheet
|
||||||
ptgs = parse(fpb, "Defines!NR_To_A1");
|
ptgs = parse(fpb, "Defines!NR_To_A1");
|
||||||
assertEquals(1, ptgs.length);
|
assertEquals(1, ptgs.length);
|
||||||
|
Loading…
Reference in New Issue
Block a user