2

Possible Duplicate:
How to insert a row between two rows in an existing excel with HSSF (Apache POI)

How can I copy the values and all the formatting of a row using HSSF. Using the MS Excel or other Spread Sheet application it is easy as copy and paste. But now I'm having problem copying a row with HSSF in Java.

My scenario right now, is I'm on the Cell:A46 and it is the last row of the table, but I still have many data to populate on the cell. I cannot simply just create a row and it cells, because I need also the formatting. And it may also break some of the formulas, because I use an excel template which have formatting after Cell:A46.

Community
  • 1
  • 1
ace
  • 6,775
  • 7
  • 38
  • 47

2 Answers2

4

Why do you not iterate trough the cells, and creating a new cell on the new row and copy the layout information from the "old" one?


BTW: If you have to do with may style information, then have a look at JXLS. It is based on POI and an be used (for example) to populate Excel files, from Excel-file based templates

Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Creating new cells is my last option. The reason why I need to copy and paste, is for future modification in the template. So I will not have a problem even the the templates for that row is change. And for now I cannot jump to JXLS, because I'm just adding new reports with the current application. As of now I'm creating a rows and its format as an interim solution. And yes I do iterating the cells and the rows is in the loop as I populate the rows. Anyway Thanks for the suggestion. – ace Apr 19 '11 at 07:33
  • JXLS saved my days .... thanks @Ralph for your suggestion! – mginius Nov 23 '15 at 15:31
3

I did a similar post that have an answer which solve this problem.

For the answer, just take a look on my other post here

Community
  • 1
  • 1
ace
  • 6,775
  • 7
  • 38
  • 47