I'm using POI to manipulate data in Excel files for a university project. I'm having trouble inserting a new column in an existing Excel. I tried to use
Cell c = createCell(int column);
c.setCellValue("someValue");
but it seems that if the column already exists, it replaces the existing data. What I need is to shift all the other columns one column to the right when I insert the new one.
I searched over the internet but I couldn't find a solution to that. Is there a way to do it, without iterating all the cells in the row and moving them one-by-one ?
To my knowledge, POI doesn't support this directly. You could create a copy of the worksheet and copy the data over, leaving room for your new column. You also need to take into consideration the need to re-write any formulas in the columns beyond your insertion point and any formulas that use those cells.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With