Apache poi异常:无效的标头签名;读取0x0010000200040009

时间:2018-06-19 11:52:37

标签: apache-poi xls apache-tika

我遇到以下错误:

org.apache.poi.poifs.filesystem.NotOLE2FileException: Invalid header signature; read 0x0010000200040009, expected 0xE11AB1A1E011CFD0 - Your file appears not to be a valid OLE2 document
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:144)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:113)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:231)
at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:167)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:254)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:226)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:205)
at main.Raport.read_excels(Raport.java:261)
at main.Raport.<init>(Raport.java:67)
at main.Avanzamento$4.actionPerformed(Avanzamento.java:138)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

在我的代码的这一部分:

wb = WorkbookFactory.create(file_excel);

我的文件是EXCEL FILE。我也用TIKA(1.18)检查过: 它给出的文件是:

application/vnd.ms-excel

我不知道问题出在哪里... 如果我在Excel中打开该文档,然后以当前格式(.xls)再次保存,一切都很好

编辑: 我正在做这样的事情,以便通过TIKA进行阅读:

package main;

import java.io.File;

import org.apache.tika.Tika;

public class Detect_type {
    public static void main(String[] args) throws Exception {

          File file = new File("C:/Users/EDP/Desktop/conf 1/2018/201812.xls");

          //Instantiating tika facade class 
          Tika tika = new Tika();

          //detecting the file type using detect method
          String filetype = tika.detect(file);
          System.out.println(filetype);
       }

}

编辑2 现在,我将路径扩展为不带“ .xls”扩展名的文件:

File file = new File("C:/Users/EDP/Desktop/conf 1/2018/201812");

并且在Windows中我也删除了扩展名: enter image description here

并收到此错误:

Exception in thread "main" java.io.FileNotFoundException: C:\Users\EDP\Desktop\conf 1\2018\201812 (The system cannot find the file specified)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at org.apache.tika.io.TikaInputStream.<init>(TikaInputStream.java:496)
    at org.apache.tika.io.TikaInputStream.get(TikaInputStream.java:267)
    at org.apache.tika.Tika.detect(Tika.java:287)
    at main.Detect_type.main(Detect_type.java:17)

0 个答案:

没有答案