簡體   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

以下是我的硒代碼,用於在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());
        } 
    }

當我使用j<row.getLastCellNum()+1進行for循環時,出現以下錯誤:“ java.lang.IllegalArgumentException:無效的列索引(16384)。EXCEL2007的允許列范圍是(0..16383)或(' A” .. 'XFD')”

好像我將row.getLastCellNum()值存儲在變量(k)中,然后在for循環中使用該變量一樣,它的工作正常。

getLastCellNum()

將返回總行加一。

API

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM