POI 遍歷工作簿的行和列獲取單元格的內容

2021-08-19 04:01:24 字數 706 閱讀 9124

本篇主要是讀取excel文件,通過遍歷行和列讀取內容。其中單元格的內容型別,需要單獨判斷讀取。

public static void main(string args) throws exception

//遍歷行row

for(int rownum = 0; rownum<=hssfsheet.getlastrownum();rownum++)

//遍歷列cell

for(int cellnum = 0; cellnum<=row.getlastcellnum();cellnum++)

system.out.print(" "+getvalue(cell));

}system.out.println();

} }

/**

* 不同型別對應不同的取值範圍

* @param cell

* @return

*/private static string getvalue(hssfcell cell)else if(cell.getcelltype()==hssfcell.cell_type_numeric)

return string.valueof(cell.getstringcellvalue());

}

總結:這裡讀取值的方法還不是很完善,讀取數字的值,整數會讀取出小數點。

pandas獲取指定的列和行

house info pd.read csv house info.csv 1 取行的操作 house info.loc 3 6 類似於python的切片操作 2 取列操作 house info price 這是讀取csv檔案時預設的第一行索引 3 取兩列 house info price trad...

pandas獲取指定的列和行

house info pd.read csv house info.csv 1 取行的操作 house info.loc 3 6 類似於python的切片操作 2 取列操作 house info price 這是讀取csv檔案時預設的第一行索引 3 取兩列 house info price trad...

POI 獲取Excel列數和行數的方法

獲取指定行,索引從0開始 hssfrow hssfsheet.getrow 1 獲取指定列,索引從0開始 hssfcell hssfrow.getcell short 6 獲取總行數 int rownum hssfsheet.getlastrownum 獲取乙個excel 中的總記錄數 int ro...