Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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

 
Ranch Hand
Posts: 118
Android Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 460
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 460
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see:

https://stackoverflow.com/questions/28394100/adding-column-to-excel-using-apache-poi
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 26914
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Objective C Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 7181
166
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Objective C Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic