【发布时间】:2020-05-07 09:38:33
【问题描述】:
我想创建一个 Excel 文件,将此文件转换为 MultipartFile.class,因为我已测试读取文件 MultipartFile,我创建了我的文件,但我不知道将 byte[] 转换为 MultipartFile,因为我的函数读取 MultipartFile。
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.getSheetAt(0);
XSSFRow row = sheet.createRow((short) 1);
row.createCell(0).setCellValue("2019");
row.createCell(1).setCellValue("11");
row.createCell(2).setCellValue("1");
row.createCell(3).setCellValue("2");
byte[] fileContent = null;
ByteArrayOutputStream bos = null;
bos = new ByteArrayOutputStream();
workbook.write(bos);
workbook.close();
fileContent = bos.toByteArray();
bos.close();
MultipartFile multipart = (MultipartFile) fileContent;
错误:
Cannot cast from byte[] to MultipartFile
【问题讨论】:
-
你说的是spring课
MultipartFile? -
我看到了这个,但是我不明白如何将byte[]转换为MultipartFile,他有transferTo(File dest),但我没有File。
-
@Maurice ,是的,我使用 Springboot,我需要类型的对象 -> MultipartFile