添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

最近使用poi从onenet导出设备信息,发现报这个异常,网上找到是都是不是Excel格式文件,另存为的问题,但是我的是poi生成的这就尴尬了

问题出在 FileOutputStream 和FileInputStream 创建位置不同

* 从onenote生成excel文件 * @param jarray 数据 * @param path 文件路径 * @param currentPage 当前页 * @param perPage 每页显示数目 public static void exportDeviceExcel (JSONArray jarray, String path, int currentPage , int perPage){ try { HSSFWorkbook workbook = null ; HSSFSheet sheet = null ; FileInputStream fis = null ; //FileOutputStream fos = new FileOutputStream(new File(path)); //(1) if (currentPage == 1 ){ //需要创建文件 //1.创建工作簿 workbook = new HSSFWorkbook(); //2.创建工作表 sheet = workbook.createSheet( "device" ); //3.1、创建头标题行; 并且设置头标题 HSSFRow row = sheet.createRow( 0 ); String[] titles = { "id" , "private" , "title" , "tags" , "location" , "protocol" , "auth_info" , "create_time" , "online" }; for ( int i= 0 ; i < titles.length; i++){ HSSFCell cell2 = row.createCell(i); cell2.setCellValue(titles[i]); } else { fis = new FileInputStream(path); workbook = new HSSFWorkbook(fis); sheet = workbook.getSheet( "device" ); //4、操作单元格;将用户列表写入excel if (jarray != null && jarray.size()> 0 ) { for ( int j = 0 ; j < jarray.size(); j++){ JSONObject json = (JSONObject) jarray.get(j); HSSFRow rowContent = sheet.createRow(j + 1 + (currentPage- 1 ) * perPage); HSSFCell idCell = rowContent.createCell( 0 ); idCell.setCellValue(json.getString( "id" )); HSSFCell privateCell = rowContent.createCell( 1 ); privateCell.setCellValue(json.getString( "private" )); HSSFCell titleCell = rowContent.createCell( 2 ); titleCell.setCellValue(json.getString( "title" )); HSSFCell tagsCell = rowContent.createCell( 3 ); tagsCell.setCellValue(json.getString( "tags" )); HSSFCell locationCell = rowContent.createCell( 4 ); locationCell.setCellValue(json.getString( "location" )); HSSFCell protocolCell = rowContent.createCell( 5 ); protocolCell.setCellValue(json.getString( "protocol" )); HSSFCell authCell = rowContent.createCell( 6 ); authCell.setCellValue(json.getString( "auth_info" )); HSSFCell timeCell = rowContent.createCell( 7 ); timeCell.setCellValue(DateUtil.date2Str(json.getDate( "create_time" ), "yyyy-MM-dd HH:mm:ss" )); HSSFCell onlineCell = rowContent.createCell( 8 ); onlineCell.setCellValue(json.getBooleanValue( "online" )? "在线" : "离线" ); FileOutputStream fos = new FileOutputStream( new File(path)); //5、输出 workbook.write(fos); fos.close(); workbook.close(); } catch (Exception e){ e.printStackTrace();

刚才开始将FileOutputStream fos = new FileOutputStream(new File(path)); 放置在最前面(1)位置,就抛出这个异常,它不能放置这个之前 fis = new FileInputStream(path); 也就是不能先创建当前文件的输出流,读取之前保证没有其他流占用该文件。
这个方法作用:第一次查询时候需要创建表,后面的查询数据就直接追加即可。

Invalid header signature ; read 0x7468206174656D3C, expected 0 xE 11 AB 1A1E011 CF D0 - Your file appears not to be a valid OLE2 document 提示无效的头部标识,但是使用 Excel 是可以正常打开的,那么另存为一下就可以了。 Invalid header signature ; read 0x0010000200040009, expected 0 xE 11 AB 1A1E011 CF D0 - Your file appears not to be avalid OLE2 document 用Java poi 3.14读取xls文件的时候出现这个异常,这是因为xls文件由第三方工具导出不是标准的Excel文件 What I want to do is ask the user if they want to create a new or select an existing Excel workbook. Selecting an existing file is no problem. However I get an error saying "Your file appears not to b... 读取word文档报错 错误信息 Invalid header signature ; read 0x3C0A0D0A0DBFBBEF, expected 0 xE 11 AB 1A1E011 CF D0 private final static String filePath = "D:/Test.doc"; public static void main(String[] args) th... 分析:用POI读取Excel文件时报错。通常的原因:是读取的文件头信息不对,http://blog.sina.com.cn/robertlizhiqiang经常出现在:         FileInputStream in = null;                   HSSFWorkbook workbook = null;                   in = new FileI... @ Invalid header signature ; read 1688935826934608, expected -2226271756974174256 今天在使用POI的HSSF读取excel的时候遇到了一个报错 Invalid header signature ; read 1688935826934608, expected -2226271756974174256 **原因:**HSSF... 这个问题是在使用poi导入excel文件时产生的: 产生的原因是:excel是从网页下载或者其他第三方软件导出的,所以它的后缀名虽然是xsl,但是它文件头签名仍然是原来的格式,所以poi不能识别,所以pio不能读取它 解决方法:使用excel打开,另存为2003版的excel,再导入就好了。                我需要读取pageoffice编辑保存后的文档内容,但是我们新建的word文件大多数都是iso88591格式的,所以读出后都是乱码,用了各种解码编码都不行,pageoffice生成的.htm文件本身是gb2312格式的,所以我用gb2312格式读出再转utf-8格式后没有出现乱码                具体核心代码如下 poi导出excel或者word的时候,报 java.io.IOException: Invalid header signature ; read 0 xE 011BDBFEFBDBFEF, expected 0 xE 11 AB 1A1E011 CF D0 解决方案: 1. 说是文件损坏,另存一下或者重新新建一个文档,然后将内容复制一份到新文档里,保存使用。 2. maven打包的时候,resource下的资源... 因为是对老项目进行修改,而且不是mavne的项目,不能随便的添加jar 包什么,(重点是使用的是Struts写的项目,非常的老) 如果是spring + maven 的项目,使用easypoi 全部注解的形式,非常容易实现导入,导出 的操作。 解决方式: 将 aaa.xlsx ------>另存为 2003 的..