2016-09-21 18 views

答えて

0

すべてのテーブル値をExcelシートに取り込むためにループを作成する必要があります。以下は私のプロジェクトで試したコードです。

public void getWebTableValues() throws Exception 
{ 
    WebElement data1=d.findElement(By.xpath("xpath of table")); 
    List<WebElement> tableRows = data1.findElements(By.tagName("tr")); 
    int rowSize=tableRows.size(); 
    System.out.println(rowSize); 
    fis1=new FileInputStream("path of the excel sheet upto ExcelSheet.xlsx"); 
    wb1=new XSSFWorkbook(fis1); 
    st1=wb1.getSheetAt(1); 
    for (int i=0; i<rowSize; i++) 
    { 
     WebElement webRow = tableRows.get(i); 
     //Get all cell values in each row 
     List<WebElement> allCells = webRow.findElements(By.tagName("td")); 
     //System.out.println(allCells.size()); 
     if(allCells.size() > 1) 
     { 
      row = st1.createRow(i); 
      for (int j=0; j<allCells.size(); j++) 
      { 
       WebElement webCell = allCells.get(j); 
       String text = webCell.getText(); 
       if(text.length()>3) 
       { 
        cell = row.createCell(j); 
        cell.setCellValue(webCell.getText()); 
       } 
       FileOutputStream fos=new FileOutputStream("path of the excel sheet upto kpmgExcelSheet.xlsx"); 
       wb1.write(fos); 
      } 
     } 
    } 

が、これはあなた

お役に立てば幸いです
関連する問題