OpenXml将ImagesPart从一个文档复制到另一个文档 [英] OpenXml Copy ImagesPart from one Document to another

查看:154
本文介绍了OpenXml将ImagesPart从一个文档复制到另一个文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

目前,我正在开发一个报告生成器,该报告生成器将读取ExcelTemplate(.xlsx),然后创建一个新文件,并写入具有所有格式和其他内容的一些单元格,行和工作表.
一切都很好,但是现在他们提出了另一个要求:
如果模板中有图像,它们也应出现在最终报告中.

我的想法是,我只需要将DrawingsPart从一个文件复制到另一个文件并正确设置关系即可.但是出现了一些问题.

第一:克隆整个零件似乎是不可能的.我对吗?有解决方案吗? (我发现了一个很肮脏的解决方法.我打开Templatefile拿走零件,不再关闭它,因此零件似乎在那里.我仅将这种方式用于测试目的)

第二如果我想更改DrawingsPart内部的图像部分的关系,我会得到一个例外:只能在包中的两个部分之间创建关系.那么如何将所需的零件放入包装中?

我不确定这是否是一种好方法,但这是我目前唯一看到的方法.

顺便说一句,对我来说,复制整个模板并随后填充它是不可能的,因为模板通常包含不使用的字段.


我应该告诉你,我的肮脏方式"将图像复制到新文件中,我认为问题出在关系的任何地方.

最佳Regads
Ray

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.


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

推荐答案

嘿,

我现在用另一种方式解决了.
我复制了原始文件,并清除了sheetdata和columns部分.之后,我像以前一样处理几乎是原始的文档,唯一的区别是-里面的图形:)
与previos版本相比的另一个小优点是:我不必关心页眉或页脚或任何新的格式设置内容.

问候
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


这篇关于OpenXml将ImagesPart从一个文档复制到另一个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆