POI讀取檔案問題

2021-10-14 15:41:49 字數 1481 閱讀 9881

依賴版本

>

>

org.apache.poigroupid

>

>

poiartifactid

>

>

3.16version

>

dependency

>

>

>

org.apache.poigroupid

>

>

poi-ooxmlartifactid

>

>

3.16version

>

dependency

>

>

>

org.apache.poigroupid

>

>

poi-ooxml-schemasartifactid

>

>

3.16version

>

dependency

>

若想使用easyexcel,請使用3.17及以上版本

workbook workbook = workbookfactory.

create

(file.

getinputstream()

);sheet sheet = workbook.

getsheetat(0

);row titlerow = sheet.

getrow(0

);if(

(titlerow.

getcell(0

).getcelltypeenum()

== celltype.blank)

&&|| objectutils.

isempty

(titlerow.

getcell(0

)))

問題:

當傳入的excel檔案的第一頁的第一行的第一列單元格為空時,我們進行判空處理。但該方法會丟擲空指標異常!

workbook workbook = workbookfactory.

create

(file.

getinputstream()

);sheet sheet = workbook.

getsheetat(0

);row titlerow = sheet.

getrow(0

);if(titlerow.

getcell(0

)== null || titlerow.

getcell(0

).getcelltypeenum()

== celltype.blank)

else

先進行cell == null的判斷,能夠避免丟擲空指標。

利用POI讀取Excel檔案

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

POI讀取Excel常見問題

最近在做乙個將excel匯入到報表中的功能,使用了poi來實現,發現poi使用有諸多不便之處,先記錄下來,以後可能考慮使用openxml。1.數值型別處理 通過poi取出的數值預設都是double,即使excel單元格中存的是1,取出來的值也是1.0,這就造成了一些問題,如果資料庫欄位是int,那麼...

POI讀取xlsx檔案後刪除原檔案的問題

最近在做遍歷資料夾並從中讀取資料的模組,其中涉及到用poi從xlsx檔案中讀取資料,並儲存到資料庫中,操作完之後肯定要刪除掉原檔案,沒想到在刪除的時候出了問題,耽誤了不少時間。讀取完資料,使用file.delete 方法來刪除原檔案,結果一直刪不掉,各種搜尋各種嘗試各種清空引數甚至用system.g...