[英]Reading multiple columns for a row from excel, in java?
我想阅读excel电子表格(.xlxs),其中包含testcases preconditions column / expected result column等。 如何读取特定行的多个列。 Everyrow(第一列)是一个测试用例名称。
我能够读取一行和两列,但不确定如何读取同一行的多个列。 我也不想在阅读时对#行#,行#进行硬编码。 有什么建议么?
Map<String,String> arrayExcelData = new Hashtable<String,String>();
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
Row row = rowIterator.next();
Cell methodNameCol = row.getCell(0);
Cell expectedResults = row.getCell(1);
if (expectedResults != null && methodNameCol !=null)
{
arrayExcelData.put(methodNameCol.getStringCellValue(),expectedResults.getStringCellValue());
}
workbook.close();
}
Row类提供了返回该Row实例中第一个和最后一个单元格(也就是列)的索引的方法。 使用这些索引迭代列:
Row row = rowIterator.next();
short firstCellNumber = row.getFirstCellNum();
short lastCellNumber = row.getLastCellNum();
for(short cellNumber = firstCellNumber; cellNumber < lastCellNumber; cellNumber++) {
Cell dataCell = row.getCell(cellNumber);
//Do something with the dataCell here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.