简体   繁体   English

在for循环中使用row.getlastcellnum()方法在Selenium中写入Excel工作表会导致java.lang.IllegalArgumentException

[英]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循环中使用该变量一样,它的工作正常。

getLastCellNum() getLastCellNum()

will return total rows PLUS ONE. 将返回总行加一。

See API API

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

相关问题 java.lang.IllegalArgumentException 尝试读取 Excel 表时出现异常 - java.lang.IllegalArgumentException exception come if trying to read an excel sheet 图像读写java.lang.IllegalArgumentException - image read and write java.lang.IllegalArgumentException 阿帕奇 POI。 使用 row.getLastCellNum() 检索非空白单元格的数量 - Apache POI. Using row.getLastCellNum() to retrieve number of non blank cells 休眠方法抛出&#39;java.lang.IllegalArgumentException&#39; - Hibernate method throwing 'java.lang.IllegalArgumentException' java.lang.IllegalArgumentException:方法不能为null - java.lang.IllegalArgumentException: Method must not be null 注册后发布方法-java.lang.IllegalArgumentException - On register post method - java.lang.IllegalArgumentException AST 方法解析中的 java.lang.IllegalArgumentException - java.lang.IllegalArgumentException in AST method parse Selenium - 使用 Apache POI 从 Excel 读取在线程“main”中给出异常 java.lang.IllegalArgumentException: Cell index must be &gt;= 0 - Selenium - Read from Excel using Apache POI gives Exception in thread "main" java.lang.IllegalArgumentException: Cell index must be >= 0 java.lang.IllegalArgumentException - java.lang.IllegalArgumentException java.lang.IllegalArgumentException - java.lang.IllegalArgumentException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM