• Post Reply Bookmark Topic Watch Topic
  • New Topic

Apache POI: How to insert a new column in an existing excel sheet?  RSS feed

 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Is there a way to insert a new column in the excel sheet without loosing the existing data in the columns.

Thanks

Krishnadhar
 
Dana Ucaed
Ranch Hand
Posts: 405
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Sure, there is a method to insert a new column.

Have you read the documentation?

 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

From what i read and understood is there is no straight method to insert a column in the excel sheet by using Apache POI, please do correct me if am wrong..

Thanks
 
Dana Ucaed
Ranch Hand
Posts: 405
6
Netbeans IDE Oracle Windows
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The below code creates row and then corresponding cell, but the situation i have is i all-ready have an xlsx sheet with 3 columns and 5 rows, i need to add a column at the beginning of the first column.


Thanks
 
Paul Clapham
Sheriff
Posts: 22701
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So for each row, move column 3 to column 4, move column 2 to column 3, and move column 1 to column 2. Now column 1 is available for you to enter your new data. No?
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Paul,

I tried doing it with the below code



but the above line shifts the entire column down by 1 row.

Thanks
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Tim,

The first link shared tough shifts the cell leaves the old cell as it is so tried modifying the code with and the entire code block fell in to place and worked like a charm. Though i worked on it previously did not pay full attention to it but a bit more concentration and work on the same worked for me.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!