将excel文档导入到数据库中

//excel文档

public String readExcel() throws InvalidFormatException, IOException {

Map<String,Object> map=new HashMap<String,Object>();

String sheet1=null;

try {

//初始化文件输入流

BufferedInputStream files =  new BufferedInputStream(new FileInputStream(file));

//新建一个工作簿

Workbook wb =  WorkbookFactory.create(files);

//读取内容

Sheet sheet = wb.getSheetAt(0);

 sheet1=sheet.getSheetName();

//获取第一个sheet页,写入sheet1数据

int length = sheet.getPhysicalNumberOfRows();

//循环读取row数据

for(int i=1;i< length;i++){

Row row = sheet.getRow(i);

String comCode=row.getCell(0).getStringCellValue();

int areaCode=(int) row.getCell(1).getNumericCellValue();

int cc=(int) row.getCell(2).getNumericCellValue();

int dd=(int) row.getCell(3).getNumericCellValue();

int ee=(int) row.getCell(4).getNumericCellValue();

int ff=(int) row.getCell(5).getNumericCellValue();

}catch(Exception e) {

e.printStackTrace();

}

return null;

}

posted @ 2018-01-04 14:59  久违的黎明  阅读(197)  评论(0编辑  收藏  举报