/**
* 读取Excel数据内容
*
* @param InputStream
*/
public void readExcelContent(InputStream is) {
try {
wb = new XSSFWorkbook(is);
sheet = wb.getSheetAt(0);
// 获取到Excel文件中的所有行数 不包括第一行的标题
int rowNum = sheet.getLastRowNum();
System.out.println("总行数:"+rowNum);
// 遍历行
for (int i = 1; i <=rowNum; i++) {
// 读取左上端单元格
Row row = sheet.getRow(i);
// 行不为空
if (row != null) {
String value = "";
// 获取到Excel文件中的所有的列
int cells = row.getPhysicalNumberOfCells();
// 遍历列
for (int j = 0; j < cells; j++) {
// 获取到列的值
Cell cell = row.getCell(j);
if (cell != null) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_FORMULA:
break;
case Cell.CELL_TYPE_NUMERIC:
value += cell.getNumericCellValue() + ",";
break;
case Cell.CELL_TYPE_STRING:
value += cell.getStringCellValue() + ",";
break;
default:
value += "0";
break;
}
}
}
System.out.println("cell:"+value);
}
}
}catch (IOException e) {
e.printStackTrace();
}
}