繁体   English   中英

How to write test result(pass/fail) in excel sheet using selenium web driver and java without hard coding row_num and Col_num in my program

[英]How to write test result(pass/fail) in excel sheet using selenium web driver and java without hard coding row_num and Col_num in my program

下面是我在 Excel 表中写入数据的程序:-

public static void write_test_result(String result, String sheet_name, String filePath,int row_num,int col_num) throws EncryptedDocumentException, FileNotFoundException, IOException
    {
        Workbook wb = WorkbookFactory.create(new FileInputStream(filePath));
        Sheet sh = wb.getSheet(sheet_name);
        sh.getRow(row_num).createCell(col_num).setCellValue(result);
        //sh.createRow(row_num).createCell(col_num).setCellValue(result);
        wb.write(new FileOutputStream(filePath));
    }

在我的程序中调用这个方法是这样的:

FileIOLibrary.write_test_result("Pass",sheet_name,FilePath, 7,5);

这里 row_num=7 和 Col_num=5 我每次都在硬编码,但我不想硬编码这些值。

如何循环调用write_test_result方法并增加row_num / Col_num每次迭代?

先感谢您。

根据您的评论,您希望迭代write_test_result方法并每次增加行/列索引,这是所需的循环结构:

int maxRowCount = 10; // set this to the total number of rows to iterate over
int maxColumnCount = 15; // set this to the total number of columns to iterate over

for (int rowCount = 1; rowCount < maxRowCount; rowCount++) {
    for (int columnCount = 1; columnCount < maxColumnCount; columnCount++) {
        FileIOLibrary.write_test_result("Pass", sheet_name, FilePath, rowCount, columnCount);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM