1. 程式人生 > >將excel文檔導入到數據庫中

將excel文檔導入到數據庫中

ade edi pan ont format obj 輸入流 puts -c

//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文檔導入到數據庫中