Excel read POI data specifying rows and columns


import
org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.FileInputStream; import java.io.InputStream; public class PoiExcelTest { public static XSSFWorkbook workbook; // 工作簿 public static XSSFSheet sheet; // 工作表 public static XSSFRow row; // public static XSSFCell cell; // public static void main(String[] args) throws Exception{ String fielName = "E:\\ExcelTest.xlsx"; String sheetName = "AI研发中心"; readExcelData(fielName,sheetName,2,1); readExcelData(fielName,sheetName,2,2); } public static void readExcelData(String fielName,String sheetName,int rownum,int cellnum) throws Exception{ InputStream in = new FileInputStream(fielName); workbook = new XSSFWorkbook(in); sheet = workbook.getSheet(sheetName); row = sheet.getRow(rownum); cell = row.getCell(cellnum); switch (cell.getCellType()){ case XSSFCell.CELL_TYPE_NUMERIC: System.out.println("第"+(rownum+1)+"行"+"第"+(cellnum+1)+"列的值: "+String.valueOf(cell.getNumericCellValue())); break; case XSSFCell.CELL_TYPE_STRING: System.out.println("第"+(rownum+1)+"行"+"第"+ (Cellnum + 1) + "value of the column:" +cell.getStringCellValue()); break; default: System.out.println("第"+(rownum+1)+"行"+"第"+(cellnum+1)+"列的值: "+cell.getStringCellValue()); break; } } }

Excel data:

Data read:

 

Guess you like

Origin www.cnblogs.com/wakey/p/11334448.html