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

时间:2015-01-22 09:21:56

标签: excel oracleapplications

在使用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;
     }

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

它的旧问题....但只是发布回答它可能对有需要的人有帮助。

在Oracle Application Testing Suite中。无需外部JAR来读/写数据。

您可以在工具中启用DataTable模块 这里给出完整的解释,http://www.testinghive.com/how-to-read-write-excel-in-oats/

//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");