使用Java使用XLS公式(Sum,avg ...)

时间:2014-01-10 09:45:27

标签: java xls jxl

如何在使用Java生成XLS文件时使用sum,avg,max和min等公式。

我正在使用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);

1 个答案:

答案 0 :(得分: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);