/* * TestFormula.java * * Created on December 11, 2002, 6:10 PM */ import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.util.HSSFColor.RED; /** * * @author dmui */ public class TestFormula { /** Creates a new instance of TestFormula */ public TestFormula() { } /** * @param args the command line arguments */ public static void main(String[] args)throws Exception { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet1 = wb.createSheet("new sheet"); //HSSFSheet sheet2 = wb.createSheet("second sheet"); //FileOutputStream fileOut = new FileOutputStream("workbook.xls"); //wb.write(fileOut); //fileOut.close(); HSSFCellStyle cs = wb.createCellStyle(); HSSFFont f = wb.createFont(); f.setFontHeightInPoints((short) 20); f.setColor((short) RED.index); f.setBoldweight(f.BOLDWEIGHT_BOLD); f.setFontName("Arial Unicode MS"); cs.setFillBackgroundColor((short)3); cs.setFont(f); HSSFRow r = sheet1.createRow(0); HSSFCell c= r.createCell( (short) 1 ); c.setCellStyle( cs ); c.setCellFormula( "SUM(A1,B1)") ; HSSFCell c2= r.createCell( (short) 0 ); c2.setCellValue("test"); c2.setCellStyle(cs); FileOutputStream fileOut = new FileOutputStream("e:\\development\\poi-test\\workbook.xls"); wb.write(fileOut); fileOut.close(); System.out.println("done"); } }