[英]Write excel sheet in Selenium using row.getlastcellnum() method in for loop causes java.lang.IllegalArgumentException
Below is my selenium code to write data in first empty column in excel sheet: 以下是我的硒代码,用于在excel工作表的第一个空列中写入数据:
public void setAllData(int sheetNumber)
{
sheet1 = wb.getSheetAt(sheetNumber);
for(int i = 0; i<rowCount+1; i++)
{
row = sheet1.getRow(i);
**int k = row.getLastCellNum();**
**for(int j = row.getLastCellNum(); j<row.getLastCellNum()+1; j++)**
**//for(int j = row.getLastCellNum(); j<k+1; j++)**
{
sheet1.getRow(i).createCell(j).setCellValue("Pass");
}
}
try {
FileOutputStream fos = new FileOutputStream(file);
wb.write(fos);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
When I used for-loop using j<row.getLastCellNum()+1
following error is coming: "java.lang.IllegalArgumentException: Invalid column index (16384). Allowable column range for EXCEL2007 is (0..16383) or ('A'..'XFD')" 当我使用j<row.getLastCellNum()+1
进行for循环时,出现以下错误:“ java.lang.IllegalArgumentException:无效的列索引(16384)。EXCEL2007的允许列范围是(0..16383)或(' A” .. 'XFD')”
Where as if I store the row.getLastCellNum()
value in a variable (k) and then used that variable in for-loop, its working fine. 好像我将row.getLastCellNum()
值存储在变量(k)中,然后在for循环中使用该变量一样,它的工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.