miércoles, 3 de junio de 2009

FORMULAS CON JEXCEL

FORMULAS CON JEXCEL

public class JExcelTesting {
//private WritableWorkbook workbook = null;
public JExcelTesting() throws IOException {
// TODO Auto-generated constructor stub
WritableWorkbook workbook = Workbook.createWorkbook(new File("C:/Testing.xls"));
WorkbookSettings wbs=new WorkbookSettings();
wbs.setCellValidationDisabled(true);
wbs.setDrawingsDisabled(true);
wbs.setFormulaAdjust(false);
wbs.setMergedCellChecking(false);
wbs.setRationalization(false);
wbs.setSuppressWarnings(true);
wbs.setUseTemporaryFileDuringWrite(false);
wbs.setAutoFilterDisabled(true);
wbs.setArrayGrowSize(20*1024*1024);
workbook.createSheet("Testing Page", 1);
WritableSheet sheet = workbook.getSheet("Testing Page");

WritableFont wf = new WritableFont(WritableFont.ARIAL, 8);
WritableCellFormat wcf = new WritableCellFormat(wf);
CellView cv = new CellView();
cv.setFormat(wcf);
WritableCellFormat wrappedText = new WritableCellFormat(WritableWorkbook.NORMAL_STYLE);
WritableCellFormat numberFormat = new WritableCellFormat(NumberFormats.FLOAT);
try {
wrappedText.setWrap(false);
Label label = new Label(0, 2, "A label record");
sheet.addCell(label);
Number number = new Number(3, 4, 3.1459);
sheet.addCell(number);
Number number1 = new Number(3, 5, 4);
sheet.addCell(number1);
sheet.addCell(new Formula(3, 6, "SUM(D5:D6)"));
workbook.write();
workbook.close();

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
JExcelTesting excelTesting = new JExcelTesting();
}

}