1.2K Star 6.2K Fork 2.7K

闲.大赋(李家智) / springboot-plus

 / 详情

DictConsoleController 里面 importExcel 导入 报错

待办的
创建于  
2021-07-13 17:35

原springboot系统中DictController,导出字典Excel报错:

通过上传(MultipartFile file) 文件获取流,然后通过jxsl解析excel文件
相应代码:

InputStream ins = file.getInputStream();
InputStream inputXLS = ins;
XLSReadStatus readStatus = mainReader.read( inputXLS, beans);

报错如下:
org.apache.poi.openxml4j.exceptions.InvalidFormatException: Your InputStream was neither an OLE2 stream, nor an OOXML stream。

如果换成写死路径的文件,用以下的方式获取流则不会出现以上问题
String path = "";
InputStream inputXLS = new BufferedInputStream(new FileInputStream(new File(path)));
XLSReadStatus readStatus = mainReader.read( inputXLS, beans);

查看源码:
Workbook#create 中 FileMagic.valueOf(is)对流进行过处理,解析出来不是OLE2 或者OOXML就会报以上error。

后端获取文件的inputStream流 之前,即文件上传的时候是有对该文件流做过什么处理吗,为啥写死的路径的文件可以导入,通过上传的文件则不能导入。

评论 (2)

tuegum 创建了任务
tuegum 关联仓库设置为闲.大赋/springboot-plus
展开全部操作日志

对了,没有对原系统中DictConsoleController.java文件做其他改动

你导入的excel应该采用下载的excel模板,你试试这个

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
29 xiandafu 1678706040
Java
1
https://gitee.com/xiandafu/springboot-plus.git
git@gitee.com:xiandafu/springboot-plus.git
xiandafu
springboot-plus
springboot-plus

搜索帮助