首页 > 数据库技术 > 详细

将excel文档导入到数据库中

时间:2018-01-04 16:10:38      阅读:227      评论:0      收藏:0      [点我收藏+]

//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;

}

将excel文档导入到数据库中

原文:https://www.cnblogs.com/huimou/p/8193434.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!