POI,XLS:消息:意外的记录类型(org.apache.poi.hssf.record.SelectionRecord)

时间:2018-11-29 16:55:58

标签: apache-poi xls

我有一个XLS文件,该文件看起来是由某些第三方报告工具生成的。 POI 4.0.0 org.apache.poi.ss.examples.ToCSV演示无法打开它进行转换:

Opening workbook [orig.XLS]
Caught an: java.lang.RuntimeException
Message: Unexpected record type (org.apache.poi.hssf.record.SelectionRecord)
Stacktrace follows:.....
java.lang.RuntimeException: Unexpected record type (org.apache.poi.hssf.record.SelectionRecord)
    at org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.<init>(RowRecordsAggregate.java:97)
    at org.apache.poi.hssf.model.InternalSheet.<init>(InternalSheet.java:183)
    at org.apache.poi.hssf.model.InternalSheet.createSheet(InternalSheet.java:122)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:355)
    at org.apache.poi.hssf.usermodel.HSSFWorkbookFactory.createWorkbook(HSSFWorkbookFactory.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook(WorkbookFactory.java:314)
    at org.apache.poi.ss.usermodel.WorkbookFactory.createHSSFWorkbook(WorkbookFactory.java:292)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:128)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:74)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:212)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:180)
    at org.apache.poi.ss.examples.ToCSV.openWorkbook(ToCSV.java:377)
    at org.apache.poi.ss.examples.ToCSV.convertExcelToCSV(ToCSV.java:340)
    at org.apache.poi.ss.examples.ToCSV.convertExcelToCSV(ToCSV.java:193)

这与POI 3.17相比要稍远一些。这是来自3.17的错误:

Opening workbook [orig.XLS]
Caught an: java.lang.IllegalArgumentException
Message: The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. Is it really an excel file? Had: [Document Summary Info, Excel1, WorkBook]
Stacktrace follows:.....
java.lang.IllegalArgumentException: The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. Is it really an excel file? Had: [Document Summary Info, Excel1, WorkBook]
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.getWorkbookDirEntryName(HSSFWorkbook.java:298)
    at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:339)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:102)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:182)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
    at org.apache.poi.ss.examples.ToCSV.openWorkbook(ToCSV.java:393)
    at org.apache.poi.ss.examples.ToCSV.convertExcelToCSV(ToCSV.java:350)
    at org.apache.poi.ss.examples.ToCSV.convertExcelToCSV(ToCSV.java:197)
    at org.apache.poi.ss.examples.ToCSV.main(ToCSV.java:682)

我在其他地方看到过,如果文件受到保护或加密,则可能会发生这种情况,但这似乎不是这种情况。

当然,该文件可以在Excel中打开。

org.apache.poi.poifs.dev.POIFSViewer(版本4.0.0)说:

POIFS FileSystem
  Property: "Root Entry"
    Name          = "Root Entry"
    Property Type = 5
    Node Color    = 0
    Time 1        = 0
    Time 2        = 131842787179025312
    Size          = 0
  WorkBook
    Property: "WorkBook"
      Name          = "WorkBook"
      Property Type = 2
      Node Color    = 1
      Time 1        = 0
      Time 2        = 0
      Size          = 316001
  Document Summary Info
    Property: "Document Summary Info"
      Name          = "Document Summary Info"
      Property Type = 2
      Node Color    = 0
      Time 1        = 0
      Time 2        = 0
      Size          = 0
  Excel1
    Property: "Excel1"
      Name          = "Excel1"
      Property Type = 1
      Node Color    = 0
      Time 1        = 131842787179008752
      Time 2        = 131842787179008752
      Size          = 0

0 个答案:

没有答案