java poi导入excel
再导入excel的时候出现问题:只能导入excel表的最后一行,报错是:Duplicate entry '142' for key 'PRIMARY'。
package com.kefu.dao;
import java.io.FileInputStream;
import
java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
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;
import com.kefu.bean.VipInfo;
public class LzxDao {
public List<VipInfo> readXls(String filePath) throws
IOException {
List<VipInfo> list = new ArrayList<VipInfo>();
FileInputStream fis = new FileInputStream(filePath);
POIFSFileSystem fs = new POIFSFileSystem(fis);
HSSFWorkbook workbook = new HSSFWorkbook(fs);//创建Excel工作簿对象
HSSFSheet sheet = workbook.getSheetAt(0);//获取第1个工作表
for(int i=1;i<sheet.getPhysicalNumberOfRows();i++){
HSSFRow row = sheet.getRow(i);
VipInfo emp=new VipInfo();
if(row==null){
continue;
}
String orgId = row.getCell(0).toString();
String orgId1 = orgId.substring(0, orgId.indexOf('.'));
emp.setVipid(Integer.parseInt((orgId1)));
HSSFCell cell2 = row.getCell(1);
if(cell2==null){
continue;
}
String card = cell2.getStringCellValue();//获取第i行的第2个单元格的数据
emp.setCard(card);
HSSFCell cell3 = row.getCell(2);
if(cell3==null){
continue;
}
String vipname = cell3.getStringCellValue();//获取第i行的第3个单元格的数据
emp.setVipname(vipname);
HSSFCell cell4 = row.getCell(3);
if(cell4==null){
continue;
}
String vipsex= cell4.getStringCellValue();//获取第i行的第4个单元格的数据
emp.setVipsex(vipsex);
HSSFCell cell5 = row.getCell(4);
if(cell5==null){
continue;