POI读取指定Excel中行与列的数据

POI读取指定Excel中行与列的数据
强烈推介IDEA2021.1.3破解激活,IntelliJ IDEA 注册码,2021.1.3IDEA 激活码  

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说POI读取指定Excel中行与列的数据,希望能够帮助大家进步!!!


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)+"列的值: "+cell.getStringCellValue()); break; default: System.out.println("第"+(rownum+1)+"行"+"第"+(cellnum+1)+"列的值: "+cell.getStringCellValue()); break; } } }

Excel数据:

POI读取指定Excel中行与列的数据

读取的数据:

POI读取指定Excel中行与列的数据

 

posted on
2019-08-11 11:46 
Ethon 阅读(
...) 评论(
...)
编辑 收藏

转载于:https://www.cnblogs.com/wakey/p/11334448.html

本文来源weixin_30595035,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/29504

发表评论