代码:
package Selenium;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
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.util.NumberToTextConverter;
public class excelReader {
//Identify Testcases coloum by scanning the entire 1st row
//once coloumn is identified then scan entire testcase coloum to identify purcjhase testcase row
//after you grab purchase testcase row = pull all the data of that row and feed into test
public static ArrayList<String> getData(String testcaseName) throws IOException
{
//fileInputStream argument
ArrayList<String> a=new ArrayList<String>();
FileInputStream fis=new FileInputStream("C://Users//Sivaranjani Gopal//Desktop//siva.xlsx");
XSSFWorkbook workbook=new XSSFWorkbook(fis);
int sheets=workbook.getNumberOfSheets();
for(int i=0;i<sheets;i++)
{
if(workbook.getSheetName(i).equalsIgnoreCase("testdata"))
{
XSSFSheet sheet=workbook.getSheetAt(i);
//Identify Testcases coloum by scanning the entire 1st row
Iterator<Row> rows = sheet.iterator();
Row firstrow= rows.next();
Iterator<Cell> ce=firstrow.cellIterator();//row is collection of cells
int k=0;
int coloumn = 0;
while(ce.hasNext())
{
Cell value=ce.next();
if(value.getStringCellValue().equalsIgnoreCase("TestCases"))
{
coloumn=k;
}
k++;
}
System.out.println(coloumn);
////once coloumn is identified then scan entire testcase coloum to identify purcjhase testcase row
while(rows.hasNext())
{
Row r=rows.next();
if(r.getCell(coloumn).getStringCellValue().equalsIgnoreCase(testcaseName))
{
////after you grab purchase testcase row = pull all the data of that row and feed into test
Iterator<Cell> cv=r.cellIterator();
while(cv.hasNext())
{
Cell c= cv.next();
if(c.getCellTypeEnum()==CellType.STRING)
{
a.add(c.getStringCellValue());
}
else{
a.add(NumberToTextConverter.toText(c.getNumericCellValue()));
}
}
}
}
}
}
return a;
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
getData("siva");
}
}
可以帮助您解决该错误:
运行代码时,我得到以下执行。
启动层初始化期间发生错误 java.lang.module.ResolutionException:模块jaxb.impl和jaxb.core将包com.sun.xml.bind.v2.model.annotation导出到模块poi
需要有关上述例外的帮助。