我需要返回一个工作簿,但转换为 JavaFile对象。目前我只知道如何将工作簿写入磁盘workbook.write(outputStream)。但是,我想返回该File对象,以便直接使用它进行进一步处理(上传到亚马逊)。
我的代码:
public File addErrorColumnToExcel(MultipartFile file, HashMap<Integer, String> errors, int newColumnIndex) throws IOException {
Workbook workbook = null;
Sheet sheet = null;
Row row;
Cell newErrorCell;
String errorText;
try {
workbook = new XSSFWorkbook(new BufferedInputStream(file.getInputStream()));
sheet = workbook.getSheetAt(FIRST_SHEET_INDEX);
} catch (IOException e) {
logger.error("cannot get the file: " + file.getOriginalFilename() + e);
}
//do some logic
return workbook; //but I need to convert this to a java File
}
Run Code Online (Sandbox Code Playgroud)