poi 3.8 使用xssf 仍然报错:The supplied data appears to be in the Office 2007+ XML. Yo

poi 3.8 使用xssf 仍然报错:The supplied data appears to be in the Office 2007+ XML. Yo

2014-11-04 19:40
import 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);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值