PR:15324- styles in formula cells; submitted by Danny Mui

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352961 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Avik Sengupta 2002-12-25 17:36:05 +00:00
parent edad0e388a
commit babbf9384f
2 changed files with 59 additions and 1 deletions

View File

@ -707,7 +707,9 @@ public class HSSFCell
FormulaRecordAggregate rec = (FormulaRecordAggregate) record; FormulaRecordAggregate rec = (FormulaRecordAggregate) record;
rec.getFormulaRecord().setOptions(( short ) 2); rec.getFormulaRecord().setOptions(( short ) 2);
rec.getFormulaRecord().setValue(0); 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); FormulaParser fp = new FormulaParser(formula+";",book);
fp.parse(); fp.parse();
Ptg[] ptg = fp.getRPNPtg(); Ptg[] ptg = fp.getRPNPtg();

View File

@ -63,6 +63,7 @@ import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.util.HSSFColor;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -225,6 +226,61 @@ extends TestCase {
3, s.getActiveCellRow()); 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) { public static void main(String [] args) {
System.out System.out
.println("Testing org.apache.poi.hssf.usermodel.TestHSSFCell"); .println("Testing org.apache.poi.hssf.usermodel.TestHSSFCell");