Java 讀取Excl檔案 (poi 3 13)

2021-07-09 15:24:18 字數 972 閱讀 9511

最近做專案遇到了讀取excel資料到資料庫做資料的初始化。於是找乙個。發現(poi-3.13)可以解決問題。可以解析兩種格式(xlsx和xls)

以下是實現的步驟

2.學習api。

接下來是還是demo來說明問題吧:

1.準備excel檔案:

2.專案的目錄結構:

**實戰:

/** 

* 讀取excel資料

* @param file

*/

public listreadexcel(file file)else if(filename.endswith("xlsx"))

//第乙個工作表

sheet sheet = wb.getsheetat(0);

//第一行的行號

int firstrowindex = sheet.getfirstrownum();

//最後一行的行號

int lastrowindex = sheet.getlastrownum();

for(int rindex = firstrowindex; rindex <= lastrowindex; rindex ++)

} }

list.add(student);

} } catch (filenotfoundexception e) catch (ioexception e)

return list;

}

結果展示:

POI讀取檔案問題

依賴版本 org.apache.poigroupid poiartifactid 3.16version dependency org.apache.poigroupid poi ooxmlartifactid 3.16version dependency org.apache.poigroupid...

java 使用poi 讀取Excel

org.apache.poi poi3.10 final org.apache.poi poi ooxml 3.10 final 讀入excel檔案,解析後返回 param file throws ioexception public static listreadexcel multipartfi...

利用POI讀取Excel檔案

前幾天實現了利用poi建立excel檔案,今天分享一下如何利用poi讀取excel檔案。要讀取的檔案內容,以下截圖已給出 下面講讀取檔案內容的方法。先建立乙個讀取excel的工具類。操作excel 的功能類 public class excelreader catch ioexception e 獲...