[英]update mailmerge field after aspose.words.Document.getMailMerge().execute
this is my first question here so bear with me please. 这是我在这里的第一个问题,请多多包涵。
I have an aspose.words.Document
object with mailmerge fields. 我有一个带有mailmerge字段的
aspose.words.Document
对象。 I need to change one of the fields more than one time. 我需要多次更改一个字段。 As far as I know once you change a
MailMerge
field with Document.getMailMerge().execute
, the field becomes plain text and stop being a field. 据我所知,一旦您使用
Document.getMailMerge().execute
更改了MailMerge
字段,该字段就会变成纯文本,而不再是一个字段。 Thats because when I use these lines of code again with different values, it doesn't work for a second time. 那是因为当我再次使用这些具有不同值的代码行时,它第二次不起作用。
doc.getMailMerge().execute(
new String[] { "title", "name", "address", "telephone", "fax", "date" },
new Object[] { "Some title", "some name", "some address", "some telephone", "some fax", "some date" });
I have two workarounds for this problem that I'm facing: 对于此问题,我有两种解决方法:
One is that I create one more Document
object and put that object through all the phases with my original Document
object except for the doc.MailMerge().execute
phase. 一种是我再创建一个
Document
对象,并将该对象与我的原始Document
对象一起放入所有阶段,除了doc.MailMerge().execute
阶段。 However the phases before MailMerge phase cost much time (for big documents) which can be measured with minutes, so I dont want to double that time. 但是,MailMerge阶段之前的阶段花费大量时间(对于大型文档),可以用几分钟来衡量,因此我不想将这个时间加倍。 I used a performance tool for it.
我为此使用了性能工具。
Second is that right before using MailMerge()
for the first time, I use Document.deepClone()
on the original document to create a second independant object. 其次,在第一次使用
MailMerge()
之前,我在原始文档上使用Document.deepClone()
创建了第二个独立对象。 With this I don't need to add those time costly code blocks for a second time, but I also haven't calculated or searched deeply for performance of this deepClone()
method. 这样,我不需要第二次添加那些耗时的代码块,但是我也没有为该
deepClone()
方法的性能进行深入的计算或搜索。 I'll add that info after I dig into that. 在深入研究后,我将添加该信息。
Long story short what I want to ask is, can I update a MailMerge field after I change it. 长话短说,我想问的是,更改后是否可以更新MailMerge字段。 If not so, is there a better workaround for this?
如果不是这样,是否有更好的解决方法?
As far as I know once you change a MailMerge field with Document.getMailMerge().execute, the field becomes plain text and stop being a field.
据我所知,一旦您使用Document.getMailMerge()。execute更改了MailMerge字段,该字段就会变成纯文本,而不再是一个字段。
Yes, you are right. 是的,你是对的。 The fields are filled with data after executing mail merge.
执行邮件合并后,这些字段将填充数据。
can I update a MailMerge field after I change it.
更改后可以更新MailMerge字段吗? If not so, is there a better workaround for this
如果不是这样,是否有更好的解决方法
If you want to execute mail merge on same document multiple times, you can either prepare the document again before merging, or create a clone. 如果要对同一文档多次执行邮件合并,则可以在合并之前再次准备文档,或者创建一个克隆。 However, it is faster to prepare the document once and than clone it before each merge.
但是,一次准备文档并比每次合并之前克隆它要快。
Please take a look at How to Produce Multiple Documents during Mail Merge . 请看一下如何在邮件合并期间生成多个文档 。
Disclosure: I am a developer at Aspose. 披露:我是Aspose的开发人员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.