dataprovider Excel文件读取如何跳过第一行

时间:2019-08-06 18:09:11

标签: java selenium-webdriver

标题

how to skip first row , if i make i=1 in for loop giving null null for 
 first row values

如何跳过第一行,如果我在for循环中将i = 1设为

第一行值

  how to skip first row , if i make i=1 in for loop giving null null for 
 first row values
   package excel2;

  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;

               import org.apache.poi.xssf.usermodel.XSSFRow;
               import org.apache.poi.xssf.usermodel.XSSFSheet;
                import org.apache.poi.xssf.usermodel.XSSFWorkbook;
               import org.testng.annotations.DataProvider;
               import org.testng.annotations.Test;

          public class DataProvider2 {
                       XSSFSheet sheet;
                     int row ;
                        int col;

        @Test(dataProvider = "excel")
     public void tc_01(String Srno, String name,String add) {
     System.out.println("name :" + Srno + "\t palce :" + name + "  add : 
           "+add);
               }
             /**
               * @author pritesh
  * @return
  * @throws IOException
  */
  @DataProvider(name = "excel")
    public Object[][] abc() throws IOException {
    FileInputStream fl = new 
   FileInputStream("C:\\Users\\pritesh\\Desktop\\x22.xlsx");

    XSSFWorkbook book = new XSSFWorkbook(fl);
    sheet = book.getSheetAt(0);
    row = sheet.getLastRowNum()+1;
    col = sheet.getRow(0).getLastCellNum();
    Object[][] obj = new Object[row][col];
    for (int i = 1; i <row; i++) {
        XSSFRow rw = sheet.getRow(i);
        for (int j = 0; j <col; j++) {
            obj[i][j] = rw.getCell(j).getStringCellValue();
           }
       }
       return obj;
       }

         }

Excel表的第一行以外的所有行都应阅读并显示在 安慰 excel表的第一行以外的所有行都应阅读并显示在 安慰 excel表的第一行以外的所有行都应阅读并显示在

控制台

Excel表的第一行以外的所有行都应阅读并显示在 控制台

0 个答案:

没有答案