将excel文档导入到数据库中

Posted huimou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将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;

}

以上是关于将excel文档导入到数据库中的主要内容,如果未能解决你的问题,请参考以下文章

请问怎么用word中的数据导入EXCEL?

教你怎样将Word表格导入到Excel中

将excel文档导入到数据库中

excel导入hive的web工具 #导入MD文档图片#

如何把excel表格的数据批量导入word模板文档内?

excel表格怎样插入到word