Java POI读取Excel的时候怎么按列读取
1个回答
2017-09-04
展开全部
public static List<String[]> getData(Workbook wb, String sheetName) {
List<String[]> list = new ArrayList<String[]>();
Sheet st = sheetName == null ? wb.getSheetAt(0) : wb.getSheet(sheetName);
for (int i = 0; i <= st.getLastRowNum(); i++) {
Row row = st.getRow(i);
if (row != null) {
String[] rowData = new String[row.getLastCellNum()];
for (int j = 0; j < row.getLastCellNum(); j++) {
Cell cell = row.getCell(j);
rowData[j] = cell.toString();
}
list.add(rowData);
}
}
return list;
}
一般都是按行读的,列的话取数据是用 list.get(i)[0],list.get(i)[1]......
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询