Java读取Excel文件指定的行列数据
前言
在做接口自动化的时候,通常会遇到数据取用及存放的问题,一般有三种方式可选择
1、数据库存取 2、表格存取 3、项目配置文件存取
这里仅展示下第二种方式表格取数据的
示例
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.File; import java.io.FileInputStream; public class ReadExcel { public static void main(String[]args){ File file = new File("/Users/llei/Downloads/test.xlsx"); try { XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new FileInputStream(file)); int tabIndex =0; Sheet sheet = xssfWorkbook.getSheetAt(tabIndex); Row row = null; Cell cell1 = null; row = sheet.getRow(0); //指定行 cell1 = row.getCell(1); //指定列 cell1.setCellType(CellType.STRING); String cellValue0 = cell1.getStringCellValue(); System.out.println(cellValue0); } catch (Exception e) { e.printStackTrace(); } } }
上一篇:
5款热门的远程控制软件,让你事半功倍