2014-01-10 98 views
0

如何在使用Java生成XLS文件時使用像sum,avg,max和min這樣的公式。使用XLS公式(Sum,avg ...)使用Java

我正在使用jxl.write。*,我已經看到了很多apache-poi的例子。使用jxl可以做同樣的事嗎?

Label label; 
WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings); 
WorkbookSettings wbSettings = new WorkbookSettings(); 
wbSettings.setLocale(new Locale("en", "EN")); 
workbook.createSheet("Report", 0); 
WritableSheet excelSheet = workbook.getSheet(0); 
label = new Label(column, row, "sample"); 
Number number = new Number(column, row, 60); 
excelSheet.addCell(label); 
excelSheet.addCell(number); 
+0

你想你的總和,平均在Java代碼或XLS? –

+0

顯示一些代碼。你有什麼嘗試。 –

+0

我使用java生成xls文件,同時生成xls文件,我想計算一些單元格的總和/平均值/最大值 –

回答

0

我是從這個鏈接Problem when using JXL Formula like SUM() AVG() STDEV() returns #VALUE! when it refers values from another sheet

String filename = "C:\\input.xls"; 
    WorkbookSettings ws = new WorkbookSettings(); 
    ws.setLocale(new Locale("en", "EN")); 
    WritableWorkbook workbook = 
    Workbook.createWorkbook(new File(filename), ws); 
    WritableSheet s = workbook.createSheet("Input", 0); 
    WritableSheet s1 = workbook.createSheet("Output", 1); 
    s1.addCell(new Number(3, 0, 5)); 
    s1.addCell(new Number(3, 1, 6)); 
    s1.addCell(new Number(3, 2, 1)); 
    s1.addCell(new Number(3, 3, 6)); 
    s1.addCell(new Number(3, 4, 1)); 
    Formula formula = new Formula(3,5,"AVERAGE(D1:D5)"); 
    s.addCell(formula);