views:

356

answers:

2

Hello,

Can anyone tell me where do I find some useful documentation on handling copying rows, cells, columns from one excel file to another, using POI? I need to insert in one blank excel file, 2 or more templates from other files, dynamic.

I also need to keep all the styles made for the group of cells that I copy. How can I do that? Nothing found on apache poi tutorial on this point.

I am using POI 3.0.1.

Thank you!

A: 

I assume the problem is data types and merged cells? It's easy enough to get and set styles and set values.

Depending on your use case, you might be able to take entire sheets from the original document, assemble the new document from those and tweak it to your liking. Even if you have to combine multiple source sheets into one target sheet, you might still be able to retrieve source rows and assemble the target document from those rows.

Tomislav Nakic-Alfirevic
I tried to copy cell by cell and it copies only the text. How do I copy everything (style, height etc), something like a clone of the cell? Where can I find some examples of the things you mention?Or how can I clone an entire region of a sheet?
gabriela
On a cell level, you can getCellStyle() for the source cell and setCellStyle() on the target cell. As for cloning "regions", POI has no such concept, but you might try copying groups of rows.While I have done some work with POI, I haven't tried these kinds of copy operations and have no examples to provide.
Tomislav Nakic-Alfirevic
A: 

...that was me some time ago...

I never could copy from one excel file to another with the exact style, but I found a solution : I used multiple worksheets instead of multiple excel files, cause style has no problem in being copied from one sheet to another as long as it is in the same workbook.

I also migrated from POI3.0.1 to POI 3.6. Far much better.

Gabriela D.