Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Write data on Excel file

Category: Selenium WebDriver
File file =    new File(filePath+""\\""+fileName);
FileInputStream inputStream = new FileInputStream(file);
Workbook workBook = null;
workBook = new XSSFWorkbook(inputStream);
Sheet sheet = workBook .getSheet(sheetName);
    int rowCount = sheet.getLastRowNum()-sheet.getFirstRowNum();
    Row row = sheet.getRow(0);
  
//Create a new row and append it at last of sheet

    Row newRow = sheet.createRow(rowCount+1);
    for(int j = 0; j < row.getLastCellNum(); j++){
        Cell cell = newRow.createCell(j);
        cell.setCellValue(dataToWrite[j]);
    inputStream.close();
    FileOutputStream outputStream = new FileOutputStream(file);
    workBook.write(outputStream);
    outputStream.close();

Leave a Reply

Your email address will not be published. Required fields are marked *