- 示例Excel - >对不起,我不允许附上图片..
- TC号|标题|的结果
- 1 |州和Vin |的失败
- 2 |州和注册码|的传递
- 3 |预订试驾|的传递
public class sampleTest{
public static void main(String[] args) throws Exception {
int iTest = 2, iTest2 = 3;
if (iTest == iTest2){
//It will pass a value into the excel (e.g. "Passed")
}
else{
//It will pass a value into the excel (e.g. "Failed")
}
}
我的计划的目标是通过从我的测试中获取通过和失败的结果来生成报告。我的主要问题是如何从excel中读取结果并将值"通过" 或"失败" 结果列。
答案 0 :(得分:1)
从here下载apache poi jar 通过这些examples来演示如何从java程序读取/写入xls数据 示例帮助代码:
public static void main(String[] args) throws IOException {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("sheet");
Row row = sheet.createRow((short) 0);
row.createCell(0).setCellValue(1.2);
row.createCell(1).setCellValue(wb.getCreationHelper().createRichTextString("This is a string"));
row.createCell(2).setCellValue(true);
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
这可能会帮助您入门。 整个流程是:
可以有多种类型的单元格查看this以获取更多信息。 要知道如何阅读excel文件:
InputStream myxls = new FileInputStream("workbook.xls");
wb = new HSSFWorkbook(myxls);
sheet = wb.getSheetAt(0); // first sheet
row = sheet.getRow(0); // third row
HSSFCell cell = (HSSFCell) row.getCell((short)1); // fourth cell
if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
System.out.println("The Cell was a String with value \" " + cell.getStringCellValue()+" \" ");
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
System.out.println("The cell was a number " + cell.getNumericCellValue());
} else {
System.out.println("The cell was nothing we're interested in");
}
有关详细信息,请参阅this
答案 1 :(得分:0)
通过库,它将成为Excel文档的界面。一个选项是Apache POI。可以从here找到Excel示例代码。
其他选项是Java Excel API。