Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey There,

currently I'm developing a Report Generator that reads an ExcelTemplate(.xlsx) and afterwards creates an new file and writes some Cells, Rows and Sheets with all the formatation and other stuff.
That all works great, but now they came up with another requirement:
If there are images in the template they should appear in the final report aswell.

My thought was I just have to copy the DrawingsPart from one file to another and set the relations correctly. But there occured some problems.

First: It seems to be Impossible to clone a whole Part. Am I right? Is there a Solution? (I found a quite dirty Workaround. I Open the Templatefile take the Part and do not close it anymore so the Part seems to be there. I do only use this way for testing purposes)

2nd If I want to change the relation of the imageparts inside of the DrawingsPart I get the Exception: A relationship can only be created between two parts in a package. So how can i get the required parts into my package?

I'm not sure if this is a good way but it's the only way i see at the moment.

btw, copying the whole template and filling it afterwards is no possible way for me because the template often contains fields that aren't used.

[Edit:]
I should tell you that my "dirty way" copys the images into the new File, i think the problem is anywhere at the relations.

Best Regads
Ray
Posted
Updated 5-Mar-12 5:37am
v2

1 solution

Hey There,

I solved it in a different way now.
I copied the original file and cleared the sheetdata and columns part. Afterwards i hand a nearly virgin document as i had it before with the only difference - there where graphics inside :)
another little advantage over the previos version is: I don't have to care about headers or footers or any new formatation stuff.

Regards
Ray
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900