Search code examples
javaapache-poijxljxls

Inserting new column in existing xls file keeping the format intact In Java


I want to insert a new column in between the existing columns of the excel which is in .xls format using Java retaining the existing format. Is there any api to do so?


Solution

  • You can use the Apache POI library to modify an Excel file.

    Quick Guide: https://poi.apache.org/components/spreadsheet/quick-guide.html

    You'll want to:

    • Load your Excel file as a Workbook.
    • Open the correct Sheet.
    • Insert your new column using Sheet#shiftColumns.
    • Save the modified Workbook back to an Excel file.