poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject cvs commit: jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel TestHSSFCell.java
Date Wed, 25 Dec 2002 17:36:05 GMT
avik        2002/12/25 09:36:05

  Modified:    src/java/org/apache/poi/hssf/usermodel HSSFCell.java
               src/testcases/org/apache/poi/hssf/usermodel
                        TestHSSFCell.java
  Log:
  PR:15324- styles in formula cells; submitted by Danny Mui
  
  Revision  Changes    Path
  1.21      +3 -1      jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
  
  Index: HSSFCell.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- HSSFCell.java	25 Dec 2002 17:27:07 -0000	1.20
  +++ HSSFCell.java	25 Dec 2002 17:36:05 -0000	1.21
  @@ -707,7 +707,9 @@
               FormulaRecordAggregate rec = (FormulaRecordAggregate) record;
               rec.getFormulaRecord().setOptions(( short ) 2);
               rec.getFormulaRecord().setValue(0);
  -            rec.setXFIndex(( short ) 0x0f);
  +            
  +            //only set to default if there is no extended format index already set
  +            if (rec.getXFIndex() == (short)0) rec.setXFIndex(( short ) 0x0f);
               FormulaParser fp = new FormulaParser(formula+";",book);
               fp.parse();
               Ptg[] ptg  = fp.getRPNPtg();
  
  
  
  1.5       +56 -0     jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java
  
  Index: TestHSSFCell.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFCell.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestHSSFCell.java	25 Dec 2002 17:27:08 -0000	1.4
  +++ TestHSSFCell.java	25 Dec 2002 17:36:05 -0000	1.5
  @@ -63,6 +63,7 @@
   import org.apache.poi.hssf.record.BOFRecord;
   import org.apache.poi.hssf.record.EOFRecord;
   import org.apache.poi.hssf.util.CellReference;
  +import org.apache.poi.hssf.util.HSSFColor;
   
   import java.io.File;
   import java.io.FileInputStream;
  @@ -225,6 +226,61 @@
               3, s.getActiveCellRow());
       }
   
  +    /**
  +     * test that Cell Styles being applied to formulas remain intact
  +     */
  +    public void testFormulaStyle()
  +            throws java.io.IOException {
  +        String readFilename = System.getProperty("HSSF.testdata.path");
  +
  +            File file = File.createTempFile("testBoolErr",".xls");
  +            FileOutputStream out    = new FileOutputStream(file);
  +            HSSFWorkbook     wb     = new HSSFWorkbook();
  +            HSSFSheet        s      = wb.createSheet("Sheet1");
  +            HSSFRow          r      = null;
  +            HSSFCell         c      = null;
  +            HSSFCellStyle cs = wb.createCellStyle();
  +            HSSFFont f = wb.createFont();
  +            f.setFontHeightInPoints((short) 20);
  +            f.setColor((short) HSSFColor.RED.index);
  +            f.setBoldweight(f.BOLDWEIGHT_BOLD);
  +            f.setFontName("Arial Unicode MS");
  +            cs.setFillBackgroundColor((short)3);
  +            cs.setFont(f);
  +            cs.setBorderTop((short)1);
  +            cs.setBorderRight((short)1);
  +            cs.setBorderLeft((short)1);
  +            cs.setBorderBottom((short)1);
  +            
  +            r = s.createRow((short)0);
  +            c=r.createCell((short)0);
  +            c.setCellStyle(cs);
  +            c.setCellFormula("2*3");
  +            
  +            wb.write(out);
  +            out.close();
  +
  +            assertTrue("file exists",file.exists());
  +
  +            FileInputStream in = new FileInputStream(file);
  +            wb = new HSSFWorkbook(in);
  +            s = wb.getSheetAt(0);
  +            r = s.getRow(0);
  +            c = r.getCell((short)0);
  +            
  +            assertTrue("Formula Cell at 0,0", (c.getCellType()==c.CELL_TYPE_FORMULA));
  +            cs = c.getCellStyle();
  +            
  +            assertNotNull("Formula Cell Style", cs);
  +            assertTrue("Font Index Matches", (cs.getFontIndex() == f.getIndex()));
  +            assertTrue("Top Border", (cs.getBorderTop() == (short)1));
  +            assertTrue("Left Border", (cs.getBorderLeft() == (short)1));
  +            assertTrue("Right Border", (cs.getBorderRight() == (short)1));
  +            assertTrue("Bottom Border", (cs.getBorderBottom() == (short)1));
  +            
  +            in.close();
  +    }    
  +    
       public static void main(String [] args) {
           System.out
           .println("Testing org.apache.poi.hssf.usermodel.TestHSSFCell");
  
  
  

Mime
View raw message