Java HSSF如何使用常量Int列数在Excel中写入结果

Java HSSF如何使用常量Int列数在Excel中写入结果,java,excel,selenium,hssf,Java,Excel,Selenium,Hssf,我是Java和Selenium新手,Selenium非常有趣,我正在使用TestNG数据驱动框架开发SeleniumWebDriver 请参阅本教程 有一个Excel实用程序,可以使用HSSF将数据写入Excel WriteResultUtility(文件路径,TestCaseName,“通过/失败/跳过”,数据集+1,“通过”) 我计划用常量文件代替硬代码。例如 公共静态最终字符串关键字\u PASS=“PASS” 公共静态最终整数列测试案例结果=10;//把它放在第10栏 因此,它将是这样

我是Java和Selenium新手,Selenium非常有趣,我正在使用TestNG数据驱动框架开发SeleniumWebDriver

请参阅本教程

有一个Excel实用程序,可以使用HSSF将数据写入Excel

WriteResultUtility(文件路径,TestCaseName,“通过/失败/跳过”,数据集+1,“通过”)

我计划用常量文件代替硬代码。例如

公共静态最终字符串关键字\u PASS=“PASS”
公共静态最终整数列测试案例结果=10;//把它放在第10栏

因此,它将是这样的,并且变得更易于管理

SuiteUbility.WriteResultUtility(文件路径\测试结果,测试用例名,常量.COL\测试\用例\结果,数据集+1,常量.关键字\通过)

我的问题是如何修改下面的代码,以便将字符串colName更改为int column number

public boolean writeResult(String wsName、String colName、int rowNumber、String Result){
试一试{
int sheetIndex=wb.getSheetIndex(wsName);
如果(sheetIndex==-1)
返回false;
int colNum=retrieveNoOfCols(wsName);
int colNumber=-1;
HSSFRow Suiterow=ws.getRow(0);
对于(int i=0;i
也许会有帮助

public  void setData(String adr,String sht,int rn,int cn,String val) throws Exception{

    FileInputStream fsIP= new FileInputStream(new File(adr)); //Read the spreadsheet that needs to be updated

    XSSFWorkbook wb = new XSSFWorkbook(fsIP); //Access the workbook

    XSSFSheet worksheet = wb.getSheet(sht); //Access the worksheet, so that we can update / modify it.

    Cell cell = null; // declare a Cell object

    cell = worksheet.getRow(rn).getCell(cn);   // Access the second cell in second row to update the value

    cell.setCellValue(val);  // Get current cell value value and overwrite the value

    fsIP.close(); //Close the InputStream

    FileOutputStream output_file =new FileOutputStream(new File(adr));  //Open FileOutputStream to write updates

    wb.write(output_file); //write changes

    output_file.close();  //close the stream   
}