From: Andrew C. Oliver Date: Mon, 2 Sep 2002 16:13:48 +0000 (+0000) Subject: Added (test first) test case for if formulas X-Git-Tag: REL_1_10~176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aa6c62ee8bb739c4f1b886aadcb523e6bb02e17a;p=poi.git Added (test first) test case for if formulas PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352833 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/testcases/org/apache/poi/hssf/data/IfFormulaTest.xls b/src/testcases/org/apache/poi/hssf/data/IfFormulaTest.xls new file mode 100644 index 0000000000..d307bee12c Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/IfFormulaTest.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java index 6ca51ddb5f..c15c54843c 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java @@ -858,6 +858,39 @@ extends TestCase { } + public void testIfFormulas() + throws java.io.IOException + { + String readFilename = System.getProperty("HSSF.testdata.path"); + + File file = File.createTempFile("testIfFormula",".xls"); + FileOutputStream out = new FileOutputStream(file); + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet s = wb.createSheet("Sheet1"); + HSSFRow r = null; + HSSFCell c = null; + r = s.createRow((short)0); + c=r.createCell((short)1); c.setCellValue(1); + c=r.createCell((short)2); c.setCellValue(2); + c=r.createCell((short)3); c.setCellFormula("MAX(A1:B1)"); + c=r.createCell((short)4); c.setCellFormula("IF(A1=D1,\"A1\",\"B1\")"); + + wb.write(out); + out.close(); + + assertTrue("file exists",file.exists()); + + FileInputStream in = new FileInputStream(readFilename+File.separator+"IfFormulaTest.xls"); + wb = new HSSFWorkbook(in); + s = wb.getSheetAt(0); + r = s.getRow(3); + c = r.getCell((short)0); + assertTrue("expected: IF(A3=A1,\"A1\",\"B1\") got "+c.getCellFormula(), ("IF(A3=A1,\"A1\",\"B1\")").equals(c.getCellFormula())); + //c = r.getCell((short)1); + //assertTrue("expected: A!A1+A!B1 got: "+c.getCellFormula(), ("A!A1+A!B1").equals(c.getCellFormula())); + in.close(); + } + public static void main(String [] args) { System.out .println("Testing org.apache.poi.hssf.usermodel.TestFormulas");