使用poi進行excel匯入並解析插入資料庫

2021-09-24 14:58:18 字數 1127 閱讀 2599

1. 匯入jar包

org.apache.poi

poi-ooxml

3.17

2. 開始匯入

public mapimportusers(multipartfile userfile)

//開啟新的執行緒來處理匯入,並使用callback接受結果

futuretask

> task = new futuretask<>(

()->userservice.importusers(userfile)

);newthread(task).start();

try

catch

(exception e)

return

resultmap;

} 3. 業務層

@override

public mapimportusers(multipartfile userfile)

else

if(filename.endswith(xls))

else

if(book != null

) system.out.println(users);

}resultmap.put("success", true

); resultmap.put("msg", "上傳成功!");

return

resultmap;

} catch

(ioexception e)

return

resultmap;

}/***  將每行資料封裝成乙個物件

*/

private listconvert(sheet sheet)

if(cell.getcolumnindex() == 3)

}if(cell.getcolumnindex() == 2)

}userlist.add(user);

}return userlist;

}

到現在為止,已經實現了excel的匯入了!

需要注意的是:這裡必須根據模板來進行資料的取出並分別賦值給不同的屬性。

Java使用poi批量匯入excel

本文為原創 經過測試可以讀取excel中的文字,這裡是按照7x 每行有7列 也可以自行設定 一 建立list用來儲存excel中的行和列,傳入本地檔案絕對路徑,或者伺服器上相對路徑,匯入可使用excel2007或excel2003 public static listreadexcel string...

java 使用poi匯入匯出excel

首先,使用poi包的話匯入poi系列包我用的3.5版本的 org.apache.poi poi ooxml 3.5 final 生活中,人們使用excel 時除了手動填寫外還有各種各樣的函式比如sum求和等如果不做任何判斷錄入的數值會和原資料不符。cell類的cell type string,cel...

poi匯入匯出excel

org.apache.poigroupid poiartifactid 3.14 beta1version dependency public private string headtextname 列頭 標題 名 private string propertyname 對應欄位名 private ...