1

I have written a code to add new row at 2nd position and then add values in the same

FileInputStream fis = new FileInputStream(theNewestFile);
    @SuppressWarnings("resource")
    XSSFWorkbook workbook = new XSSFWorkbook(fis);
    XSSFSheet spreadsheet = workbook.getSheetAt(0);
    XSSFRow row;

    try {
        System.out.println(filename1);
        InputStream myxls = new FileInputStream(filename1);

        workbook = new XSSFWorkbook(myxls);
          int rows=spreadsheet.getLastRowNum();
        spreadsheet.shiftRows(2, rows, 1);
        spreadsheet.createRow(1);
        spreadsheet.getRow(1).createCell(0).setCellValue(column1Val);
        FileOutputStream fileOut;

        fileOut = new FileOutputStream(theNewestFile);
        workbook.write(fileOut);
        fileOut.close();
    } 
Dolly
  • 97
  • 3
  • 18

0 Answers0