通过MS Excel将数据输入/导出到OATS脚本中

通过MS Excel将数据输入/导出到OATS脚本中,excel,oracleapplications,Excel,Oracleapplications,在使用OATS工具时,试图从Excel工作表中获取输入数据时,它总是进入函数的catch块。下面是编写的脚本。请帮助我们解决这个问题 public String getInputfromExcel(int argColumnNumber,int argRowNumber)throws Exception { String inputExcelName = dataPath+".xlsx"; String cellContent = "12";

在使用OATS工具时,试图从Excel工作表中获取输入数据时,它总是进入函数的catch块。下面是编写的脚本。请帮助我们解决这个问题

public String getInputfromExcel(int argColumnNumber,int argRowNumber)throws Exception
    {
          String inputExcelName = dataPath+".xlsx";
          String cellContent = "12";
          try 
          {
                Workbook workbook = Workbook.getWorkbook(new File(inputExcelName));
                Sheet sheet = workbook.getSheet(0);
                Cell a1 = sheet.getCell(argColumnNumber, argRowNumber);
                cellContent = (a1.getContents()).toString(); 
                System.out.println(cellContent.toString());
                workbook.close();
          }
          catch (Exception e) 
          {
            addReport("Getting Input From Excel", "Fail","Exception while reading value from excel sheet");

          }
          return cellContent;
     }

阿克塞尔提出了这一点。另外,如果我没记错的话,function sheet.getCell(arg1,arg2)的第一个参数是rowNumber,第二个参数是columnNumber(这两个值都是基于0的索引)。

它的老问题……但只要发布答案,可能会对需要的人有所帮助

在Oracle应用程序测试套件中。不需要外部JAR来读取/写入数据

您可以在工具中启用DataTable模块 这里给出了完整的解释

//定义要读取的工作表名称,并提供逗号分隔以读取多个工作表
字符串sheetName=“Sheet1”;
//提及excel工作表路径
String strFile=“C:\\Demo\\test.xls”;
//定义了用于添加要读取的图纸的数组列表
List sheetList=new ArrayList();
图纸列表。添加(图纸名称);
//Iports单张1
导入表(strFile,sheetList,true,true);
//获取行数
信息(“行总数:+datatable.getRowCount());
int rowcount=datatable.getRowCount();
//循环以读取所有行

for(int i=0;i在catch块中输入一个
e.printStackTrace();
。这样您就可以在stderr中看到问题所在。谢谢您,Alex。但是,当我看到控制台消息时,它会显示以下错误。请您能帮我调试此错误吗。java.lang.ArrayIndexOutOfBoundsException:2 at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)在script.getInputfromExcel(script.java:196)在script.run(script.java:117)在oracle.oats.scripting.modules.basic.api.IteratingVUser.run(IteratingVUser.java:350)在oracle.oats.scripting.modules.basic.api.internal.IteratingAgent.run(IteratingAgent.java:799)在java.run(Thread.java:619)上那么如何解释堆栈跟踪:在script.getInputfromExcel(script.java:196)的jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)处有一个
java.lang.ArrayIndexOutOfBoundsException
getInputfromExcel
是您的代码。那么第196行是哪一行呢?我怀疑
单元格a1=sheet.getCell(argColumnNumber,argRowNumber);
。因此getCell越界。那么,如果发生错误,
argColumnNumber
argRowNumber
的值是什么?单元格(argColumnNumber,argRowNumber)真的在存储的excel文件中吗?
//Define Sheet name to be read, and provide comma seperated to read multiple sheets
String sheetName = "Sheet1";
//Mention excel sheet path
String strFile= "C:\\Demo\\test.xls";

//Defined array list to add Sheets to read
List sheetList = new ArrayList();
sheetList.add(sheetName);
// Iports Sheet1
datatable.importSheets(strFile, sheetList, true, true);
//get rowcount
info("Total rows :"+datatable.getRowCount());
int rowcount=datatable.getRowCount();
//Loop to read all rows
for (int i=0;i<rowcount;i++)
{
//Set current row fromw here you need to start reading, in this case start from first row
datatable.setCurrentRow(sheetName, i);
String strCompany=(String) datatable.getValue(sheetName,i,"Company");
String strEmpFName=(String) datatable.getValue(sheetName,i,"FirstName");
String strEmpLName=(String) datatable.getValue(sheetName,i,"LastName");
String strEmpID=(String) datatable.getValue(sheetName,i,"EmpID");
String strLocation=(String) datatable.getValue(sheetName,i,"Location");

//prints first name and last name
System.out.println("First Name : "+strEmpFName+", Last Name : "+strEmpLName);

//Sets ACTIVE column in excel sheet to Y
String strActive="Y";
datatable.setValue(sheetName, i, datatable.getColumn(sheetName, datatable.getColumnIndex("Active")), strActive);

}

//Updates sheet with updated values ie ACTIVE column sets to Y
datatable.exportToExcel("C:\\Demo\\test1.xlsx");