public static AttachmentPO uploadFile(AttachmentApi attachmentApi,Workbook wb, String filename) {
// 在本地创建临时文件
wb.setForceFormulaRecalculation(true);
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
File excelFile = FileUtil.file(FileUtil.getTmpDirPath() + File.separator + filename);
FileItem item = (new DiskFileItemFactory()).createItem("file", "multipart/form-data", true, excelFile.getName());
OutputStream outputStream = null;
InputStream input = null;
OutputStream os = null;
try {
outputStream = new FileOutputStream(excelFile);
wb.write(outputStream);
input = new FileInputStream(excelFile);
os = item.getOutputStream();
IoUtil.copy(input, os);
//删除本地附件信息
excelFile.delete();
MultipartFile multipartFile = new CommonsMultipartFile(item);
return attachmentApi.uploadFile(multipartFile).getData();
} catch (FileNotFoundException e) {
throw new LunaBusinessException(e);
} catch (IOException e) {
throw new LunaBusinessException(e);
} finally {
IoUtil.close(outputStream);
IoUtil.close(input);
IoUtil.close(os);
}
}
如上文添加
wb.setForceFormulaRecalculation(true);
wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
新文件的sum公式就起作用了