将错误的网页/Excel 转换为正确的 Excel

问题描述

我有一个应用程序可以自动处理一系列 Excel 文件,但我有一个问题。对于某些文件,我似乎有一个带有 .xls 文件扩展名的 html 文件(在 excel 中打开会给出损坏警告,重新保存显示它想要另存为 html)。

使用 Apachi POI 时:

try (Workbook wkbk = WorkbookFactory.create(myCorruptFile)) {
//myCorruptFile is of type File

这无法处理 apache poi NotOLE2FileException 错误如下

Invalid header signature; read 0x0A0D3E6C6D74683C,expected 0xE11AB1A1E011CFD0 - Your file appears not to be a valid OLE2 document,{ }

如果我手动重新保存为 .xls 文件,该文件将得到适当处理,但是有没有办法通过 java 11 检测和重新保存/转换此文件?与自动转换相比,手动转换文件对我来说不是一种选择。

myCorruptFile.getContentType()内容类型指定为:

application/vnd.ms-excel

并且使用 Apache Tika 检测到的类型为:

tika.detect(myCorruptFile.getBytes())

文本/html

(我的 maven pom 没有过滤)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)