]> source.dussan.org Git - poi.git/commitdiff
Added (test first) test case for if formulas
authorAndrew C. Oliver <acoliver@apache.org>
Mon, 2 Sep 2002 16:13:48 +0000 (16:13 +0000)
committerAndrew C. Oliver <acoliver@apache.org>
Mon, 2 Sep 2002 16:13:48 +0000 (16:13 +0000)
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

src/testcases/org/apache/poi/hssf/data/IfFormulaTest.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java

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 (file)
index 0000000..d307bee
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/IfFormulaTest.xls differ
index 6ca51ddb5f073753a5ca0a531a8fd70eabfcb7f2..c15c54843c41aba6366a23acfa67c7ba698dae5f 100644 (file)
@@ -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");