接口自动化测试-POI框架读取excel表格数据

接口自动化测试-POI框架读取excel表格数据_第1张图片

package logpost;

import java.io.File;
import java.io.IOException;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class ExcelUtil {
	/***
	 * 1.获取workbook对象
	 * 2.获取sheet对象
	 * 3.获取行
	 * 4.获取列
	 * @return
	 */
	public static Object[][] name(String excelPath,int startRow,int endRow,int startCell,int endCell) {
		//String excelPath="E:\\InterfaceAuto\\LogCase.xls";
		Object[][]datas=new Object[endRow-startRow+1][endCell-startCell+1];
//		1.获取workbook对象
		//File file=new File(excelPath);
		try {
			Workbook workbook=WorkbookFactory.create(new File(excelPath));
//			2.获取sheet对象
			Sheet sheet=workbook.getSheet("log");
//			3.获取行
//			4.获取列
			for(int i=startRow-1;i

读取结果:

接口自动化测试-POI框架读取excel表格数据_第2张图片

 

你可能感兴趣的:(接口自动化测试(Java))