POI读取指定Excel中行与列的数据
Posted wakey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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中行与列的数据的主要内容,如果未能解决你的问题,请参考以下文章
JAVA poi 数据库表里的内容输出到Excel表格指定位置