Fixed XSSFName and test cases
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@718651 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0ad2331f88
commit
d2e7c9c832
@ -16,10 +16,11 @@
|
||||
==================================================================== */
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.ss.formula.FormulaParser;
|
||||
import org.apache.poi.ss.formula.FormulaType;
|
||||
import org.apache.poi.ss.usermodel.Name;
|
||||
import org.apache.poi.ss.util.AreaReference;
|
||||
import org.apache.poi.util.POILogFactory;
|
||||
import org.apache.poi.util.POILogger;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
|
||||
|
||||
/**
|
||||
@ -163,7 +164,7 @@ public final class XSSFName implements Name {
|
||||
* @deprecated (Nov 2008) Misleading name. Use {@link #setFormula(String)} instead.
|
||||
*/
|
||||
public void setReference(String ref){
|
||||
setFormula(ref);
|
||||
setFormula(ref);
|
||||
}
|
||||
/**
|
||||
* Returns the reference of this named range, such as Sales!C20:C30.
|
||||
@ -181,7 +182,16 @@ public final class XSSFName implements Name {
|
||||
* @throws IllegalArgumentException if the specified reference is unparsable
|
||||
*/
|
||||
public void setFormula(String formulaText) {
|
||||
// TODO parse formula and throw IllegalArgumentException if problem
|
||||
XSSFEvaluationWorkbook fpb = XSSFEvaluationWorkbook.create(workbook);
|
||||
Ptg[] ptgs;
|
||||
try {
|
||||
ptgs = FormulaParser.parse(formulaText, fpb, FormulaType.CELL); // TODO - use type NAMEDRANGE
|
||||
} catch (RuntimeException e) {
|
||||
if (e.getClass().getName().startsWith(FormulaParser.class.getName())) {
|
||||
throw new IllegalArgumentException("Unparsable formula '" + formulaText + "'");
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
ctName.setStringValue(formulaText);
|
||||
}
|
||||
|
||||
|
@ -35,26 +35,33 @@ public final class AllXSSFUsermodelTests {
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite result = new TestSuite(AllXSSFUsermodelTests.class.getName());
|
||||
result.addTestSuite(TestXSSFBorder.class);
|
||||
result.addTestSuite(TestXSSFBugs.class);
|
||||
result.addTestSuite(TestXSSFCellFill.class);
|
||||
result.addTestSuite(TestXSSFHeaderFooter.class);
|
||||
result.addTestSuite(TestXSSFSheetComments.class);
|
||||
result.addTestSuite(TestColumnHelper.class);
|
||||
result.addTestSuite(TestHeaderFooterHelper.class);
|
||||
result.addTestSuite(TestFormulaEvaluatorOnXSSF.class);
|
||||
result.addTestSuite(TestSheetHiding.class);
|
||||
result.addTestSuite(TestXSSFBugs.class);
|
||||
result.addTestSuite(TestXSSFCell.class);
|
||||
result.addTestSuite(TestXSSFCellStyle.class);
|
||||
result.addTestSuite(TestXSSFComment.class);
|
||||
result.addTestSuite(TestXSSFDialogSheet.class);
|
||||
result.addTestSuite(TestXSSFDrawing.class);
|
||||
result.addTestSuite(TestXSSFFont.class);
|
||||
result.addTestSuite(TestXSSFFormulaEvaluation.class);
|
||||
result.addTestSuite(TestXSSFHeaderFooter.class);
|
||||
result.addTestSuite(TestXSSFHyperlink.class);
|
||||
result.addTestSuite(TestXSSFName.class);
|
||||
result.addTestSuite(TestXSSFPicture.class);
|
||||
result.addTestSuite(TestXSSFPictureData.class);
|
||||
result.addTestSuite(TestXSSFPrintSetup.class);
|
||||
result.addTestSuite(TestXSSFRichTextString.class);
|
||||
result.addTestSuite(TestXSSFRow.class);
|
||||
result.addTestSuite(TestXSSFSheet.class);
|
||||
result.addTestSuite(TestXSSFWorkbook.class);
|
||||
|
||||
result.addTestSuite(TestXSSFFont.class);
|
||||
result.addTestSuite(TestXSSFPrintSetup.class);
|
||||
result.addTestSuite(TestXSSFBorder.class);
|
||||
result.addTestSuite(TestXSSFCellFill.class);
|
||||
result.addTestSuite(TestXSSFSheetComments.class);
|
||||
|
||||
result.addTestSuite(TestColumnHelper.class);
|
||||
result.addTestSuite(TestHeaderFooterHelper.class);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class TestXSSFName extends TestCase {
|
||||
assertEquals(ref1, name1.getReference());
|
||||
assertEquals("Test1", name1.getSheetName());
|
||||
|
||||
String ref2 = "Testing Named Ranges!$A$1:$B$1";
|
||||
String ref2 = "'Testing Named Ranges'!$A$1:$B$1";
|
||||
name1.setReference(ref2);
|
||||
//XSSFName#setReference stores the reference in canonical form and puts the sheet name in single quotes
|
||||
assertEquals("'Testing Named Ranges'!$A$1:$B$1", name1.getReference());
|
||||
|
Loading…
Reference in New Issue
Block a user