您的位置:首页 > 移动开发

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: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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: