读取Excel错误:无效头签名。如何解决? [英] Excel read error : Invalid header signature. How to resolve?

查看:2475
本文介绍了读取Excel错误:无效头签名。如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上传从browser运行一台Excel文件。我使用POI罐子。但得到的错误
无效的头签名;阅读3255307777713450285,预计-2226271756974174256

I am uploading one excel file from browser. I am using POI jar. But getting error Invalid header signature; read 3255307777713450285, expected -2226271756974174256

下面的两个JSP文件我已经使用:
JSP 1:

below the two jsp files i have used: JSP 1:

<form action="Upload.jsp" enctype="MULTIPART/FORM-DATA" method=post >
  <input type="file" name="filename" />
  <input type="submit" value="Upload" />
</form>

JSP 2:Upload.jsp

JSP 2:Upload.jsp

try{
        InputStream file = request.getInputStream();
        POIFSFileSystem myFileSystem = new POIFSFileSystem(file);
        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);
        HSSFSheet mySheet = myWorkBook.getSheetAt(0);
        Iterator rowIter = mySheet.rowIterator();
        rowIter.next(); 
        while (rowIter.hasNext()) {
            HSSFRow myRow = (HSSFRow) rowIter.next();
            Iterator cellIter = myRow.cellIterator();
            cellIter.next();
            System.out.println(((HSSFCell)cellIter.next()).toString());
        }


    }catch(Exception ex){
        System.out.println(ex.getMessage());
    }

但得到的错误在行POIFSFileSystem myFileSystem =新POIFSFileSystem(文件);

But getting the error at line POIFSFileSystem myFileSystem = new POIFSFileSystem(file);

如何resovle这个问题?

How to resovle this problem?

推荐答案

由于您的文件实际上不是一个Excel .xls文件你收到此错误,这是别的东西。

You're getting this error because your file isn't actually an Excel .xls file, it's something else.

我建议你尝试打开在记事本的文件,看它在那里。几乎所有这种类型的错误,最终被一个.csv或.html文件已被重命名为.xls。 Excel将愉快地加载HTML文件(渲染表作为S preadsheet)和CSV文件,而不会警告你,你已经得到了他们错误的扩展名。

I'd suggest you try opening the file in Notepad, and look at it there. Almost all errors of this type end up being that a .csv or .html file has been renamed to .xls. Excel will happily load html files (rendering the table as the spreadsheet) and csv files, and doesn't warn you that you've got the wrong extension on them.

请注意,如果您重命名一个.xlsx文件到.xls和传递到POI的POIFSFileSystem或HSSFWorkbook,你会得到一个更具体的错误警告你,你已经有了一个.xlsx文件来代替。你只是得到这个错误,因为POI已经完全不知道你的文件是什么,只知道它不是一个的.xls

Note that if you rename a .xlsx file to a .xls and pass that to POI's POIFSFileSystem or HSSFWorkbook, you'll get a more specific error warning you that you've got a .xlsx file instead. You're only getting this error because POI has absolutely no idea what your file is, only that it's not a .xls

这篇关于读取Excel错误:无效头签名。如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆