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,但仍然,报原来的错!
各位大牛,怎么解?
在线等!
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,但仍然,报原来的错!
各位大牛,怎么解?
在线等!
解决方案