The supplied data appears to be in the Office 2007+ XML
来源:互联网 发布:百度网盘mac版本 编辑:程序博客网 时间:2024/05/21 07:01
1、错误描述
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:152)at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:140)at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:302)at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:87)at com.you.print.ExcelUtils.replaceModel(ExcelUtils.java:20)at com.you.print.TestReplaceExcel.main(TestReplaceExcel.java:28)
2、错误原因
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:152)at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:140)at org.apache.poi.poifs.filesystem.NPOIFSFileSystem.<init>(NPOIFSFileSystem.java:302)at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:87)at com.you.print.ExcelUtils.replaceModel(ExcelUtils.java:20)at com.you.print.TestReplaceExcel.main(TestReplaceExcel.java:28)/** * */package com.you.print;import java.util.ArrayList;import java.util.List;/** * @author Administrator * */public class TestReplaceExcel {/** * @param args */public static void main(String[] args) {List<ReplaceExcelData> list = new ArrayList<ReplaceExcelData>();ReplaceExcelData red = new ReplaceExcelData();red.setColumn(2);red.setRow(6);red.setKey("1");red.setValue("111111");list.add(red);ExcelUtils.replaceModel(list, "D:\\myeclipseworkspces\\Print\\model\\WeightBill.xlsx", "D:\\myeclipseworkspces\\Print\\model\\Bill.xlsx");}}package com.you.print;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.List;import org.apache.poi.hssf.usermodel.HSSFCell;import org.apache.poi.hssf.usermodel.HSSFRow;import org.apache.poi.hssf.usermodel.HSSFSheet;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class ExcelUtils {public static boolean replaceModel(List<ReplaceExcelData> datas, String sourceFilePath, String targetFilePath) { boolean bool = true; try { POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream(sourceFilePath)); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); for (ReplaceExcelData data : datas) { //获取单元格内容 HSSFRow row = sheet.getRow(data.getRow()); HSSFCell cell = row.getCell((short)data.getColumn()); String str = cell.getStringCellValue(); //替换单元格内容 str = str.replace(data.getKey(), data.getValue()); //写入单元格内容 cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(str); } // 输出文件 FileOutputStream fileOut = new FileOutputStream(targetFilePath); wb.write(fileOut); fileOut.close(); } catch (Exception e) { bool = false; e.printStackTrace(); } return bool; } }关键问题的原因还是excel2003和excel2007版本的问题
3、解决办法
(1)判断文件后缀名是xls,还是xlsx
(2)如果是xls,使用HSSFWorkbook;如果是xlsx,使用XSSFWorkbook
0 1
- The supplied data appears to be in the Office 2007+ XML
- The supplied data appears to be in the Office 2007+ XML
- The supplied data appears to be in the Office 2007+ XML
- poi 3.8 使用xssf 仍然报错:The supplied data appears to be in the Office 2007+ XML. Yo
- The document appears to be corrupted and cannot be loaded
- 断电或强制退出后VMware虚拟机出现The virtual machine appears to be in u...
- 断电或强制退出后VMware虚拟机出现The virtual machine appears to be in use
- hadoop2.0报错“There appears to be a gap in the edit log”
- the greeter application appears to be crashing的解决
- Your PHP installation appears to be missing the MySQL extension.。。。。。。
- The capture file appears to be damaged or corrupt.
- Intellij 14 the supplied javaHome seems to be invalid
- The download file appears to be corrupted. Please refer to the Troubleshooting section of the Insta
- 断电或强制退出后VMware虚拟机出现The virtual machine appears to be in use无法启动问题解决
- 【转】断电或强制退出后VMware虚拟机出现The virtual machine appears to be in use无法启动问题解决
- There appears to be a gap in the edit log. We expected txid 1, but got txid 16
- java.io.IOException: There appears to be a gap in the edit log. We expected txid 41, but got txid
- the data that is in the table is from excel, so the data to be read can changed?
- CSS水平居中元素方法及反思
- 把排序数组转换为高度最小的二叉搜索树
- L2-021. 点赞狂魔
- 如何使/etc/profile中修改的配置立刻生效?
- 【ESP8266】关于调试fatal exception/自动重启的一些经验分享
- The supplied data appears to be in the Office 2007+ XML
- linux下的僵尸进程及atexit函数的使用及验证
- 【动态规划】zoj Course Selection System
- 动态规划练习题-16(踩方格)
- 练习
- Camera2谷歌官方文档(1) 概述
- L3-013. 非常弹的球
- CentOS 7 编译安装Python2.6.1
- C#编写动态链接库类库dll文件