poi 3.8 使用xssf 仍然报错:The supplied data appears to be in the Office 2007+ XML. Yo
2016-04-08 16:59
513 查看
poi 3.8 使用xssf 仍然报错:The supplied data appears to be in the Office 2007+ XML. Yo
2014-11-04 19:40import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public void insertCardByExcel(String fileUrl)
{
List<Card> list = new ArrayList<Card>();
// 获取文件的输入流对象
InputStream is;
try {
is = new FileInputStream(fileUrl);
POIFSFileSystem fs = new POIFSFileSystem(is);
XSSFWorkbook wb = new XSSFWorkbook(is);
// 获取第一个Sheet页
XSSFSheet sheet = wb.getSheetAt(0);
// 获取Sheet页的行数
int rowNum = sheet.getLastRowNum();
// 将内容放入List中
for(int i = 1;i < rowNum;i++)
{
XSSFRow row = sheet.getRow(i);
String a1 = this.getStringCellValue(row.getCell(1)).trim();
String a2= this.getStringCellValue(row.getCell(3)).trim();
String a3= this.getStringCellValue(row.getCell(5)).trim();
String a4= this.getStringCellValue(row.getCell(7)).trim();
String a5= this.getStringCellValue(row.getCell(9)).trim();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我以前用的是HSSF,因为用到了Excel 2007,报错:
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)
后来就换成了XSSF,但仍然,报原来的错!
各位大侠,怎么解?
在线等!
回复讨论(解决方案)
缺少xmlbeans-2.3.0.jar,将XSSFWorkbook wb = new XSSFWorkbook(is); // 获取第一个Sheet页
XSSFSheet sheet = wb.getSheetAt(0);
改成
Workbook wbs = WorkbookFactory.create(f.getInputStream());
Sheet childSheet = wbs.getSheetAt(0);
相关文章推荐
- Android 聊天界面背景图片不顶上去内容顶上去解决方法
- Android——Handler 多线程
- Unity3d发布webplayer 部署到IIS
- Android学习全套视频(64G)
- Android中Fragment学习笔记
- Android存储之ShredPreferences
- iOS __runtime
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- qwebview打开图片链接
- WebView——WebViewClient/WebChomeClient
- appcan快速学习
- android删除系统内置apk(system/app目录下apk)
- 2016-4-8工作日志:Android获取WiFi信号强度
- [Unity] 官方文档Coroutines的应用场景
- Appium python API 总结
- 异常摘要
- Anyoffice -HTML5大赛 悦心(基于H5开发安卓音乐app)-项目总结
- Unity3d发布webplayer 部署到IIS
- Android ORM框架 greenDao使用
- android项目总结