我目前正在用 Java 编写一个程序,该程序将在 excel 中运行多个测试并立即生成报告。我能够通过 excel 进行读写,通过或失败的结果显示在结果列中。我能够在 excel 中编写这些,但是通过在单元格上提供默认值(例如默认值),因此代码只会覆盖它。我想在评论栏写评论,但我不知道如何在空单元格中写。这是我正在生成的报告的屏幕截图(可用图像的链接)以及用于在 excel 中读取和写入的代码。
FileInputStream fileInputStream = new FileInputStream("ReportExcel.xls");
HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream);
HSSFSheet worksheet = workbook.getSheetAt(0);
fileInput csvInputFile = new fileInput();
String[] sReturnValue = csvInputFile.arrayReturnSingleValue("fileInput.csv");
if (prodnameresult.equals(prodname) ){
Pass++;
totalResult++;
System.out.println ("Testcase1: Branding-Customised Product Name is PASSED");
//Harold's Input
HSSFRow row = worksheet.getRow(1);
HSSFCell cell = row.getCell((short) 4);
cell.setCellValue("Passed");
}
else{
Fail++;
totalResult++;
System.out.println("Testcase1: Branding-Customised Product Name is FAILED");
//assertEquals(prodnameresult.equals(prodname), true);
//Harold's Input
HSSFRow row = worksheet.getRow(1);
HSSFCell cell = row.getCell((short) 4);
cell.setCellValue("Failed");
}
//Harold's Input
FileOutputStream os = new FileOutputStream("ReportExcel.xls");
workbook.write(os);
os.close();
}
报告: