Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache POI: How to insert column in Excel file

Tags:

java

excel

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 ?

like image 867
user510058 Avatar asked Nov 16 '10 21:11

user510058


1 Answers

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.

like image 152
Brad Gardner Avatar answered Oct 15 '22 02:10

Brad Gardner