0
votes

I want to clear contents of 3 columns in excel sheet(.xlsx file) using java before execution of my selenium script. i am using XSSFWorkbook(Apache poi) for read and write data to excel sheet.There are 5 columns in excel sheet.I want to clear 3 column contents and remaining column content should keep like before.

please help me how can i achieve that?

1

1 Answers

0
votes
FileInputStream objFileInputStream = new FileInputStream(new File(
                    Xlsx_File_path.xlsx));
XSSFWorkbook objWorkbook = new XSSFWorkbook(objFileInputStream);
XSSFSheet objSheet = objWorkbook.getSheetAt(0);
Cell cell = null;
int row=[start of row]
int cell=[your cell]


//iterate the below code as you want
//code
  cell = objSheet.getRow(rows).getCell(cell);
  cell.setCellValue("")
//code

objFileInputStream.close();
FileOutputStream output_file = new FileOutputStream(new File(
                    finalXlsx.xlsx));
    objWorkbook.write(output_file);
            output_file.close();