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();
    } 
3
  • Does this answer your question? Create Excel file in Java Commented Oct 30, 2019 at 5:33
  • I need to update the existing excel instead of creating new excel. Please help @www.hybriscx.com Commented Oct 30, 2019 at 5:35
  • Could you edit your post to provide more information or more precise description? Commented Oct 30, 2019 at 7:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.