Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Nov 02, 2013 9:51 am

How to manually parse all MERGEFIELD inside header?

Standard mailmerge works like a charm with MERGEFIELD inside main part of document.

But would like to manually "mailmerge" MERGEFIELD in header. Is it possible, any example?

krhyll
 
Posts: 23
Joined: Fri Nov 11, 2011 12:27 pm

Mon Nov 04, 2013 2:54 am

Hello Kristian,

Thanks for your inquiry. Sorry for late reply as weekend.
For your need, please refer to the demo in the attament, which doesn't include the dll as they are large, please quote them and try. If it doesn't fulfill your need, please provide us your template if convenience.

Best Regards,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Nov 04, 2013 7:17 am

Hi Gary,

Thanks a lot for demo here. Will test it and it seems like a simple solution.
Could you please point to where in your documentation the functionality of this method is described?
- doc.MailMerge.Execute(filedNames, filedValues);

I did manage to find a solution as shown in code below. The catch in my code is that the MERGEFIELDs must be located inside a TEXTBOX, but it works somehow.

Code: Select all
                '
                ' Post mailmerge in header
                '
                For Each para As Paragraph In document.Sections(0).HeadersFooters.Header.Paragraphs
                    For Each item As Object In para.Items
                        If TypeOf item Is Spire.Doc.Fields.TextBox Then
                            For Each paras As Paragraph In TryCast(item, Spire.Doc.Fields.TextBox).ChildObjects
                                For Each paraItem As Object In paras.Items
                                    If TypeOf paraItem Is Spire.Doc.Fields.MergeField Then
                                        Dim paraItemMergeField As Spire.Doc.Fields.MergeField = TryCast(paraItem, Spire.Doc.Fields.MergeField)
                                        Dim mmValue As String = ""
                                        Try
                                            mmValue = CStr(ds.Tables("Prosjekt").Rows(0)(paraItemMergeField.FieldName))
                                        Catch ex As Exception

                                        End Try
                                        'paraItemMergeField.FieldName = "Header:FieldName:" + mmValue
                                        'paraItemMergeField.FieldText = "Header:FieldText:" + mmValue
                                        'paraItemMergeField.Pattern = "Header:Pattern:" + mmValue
                                        'paraItemMergeField.TextAfter = "Header:TextAfter:" + mmValue
                                        paraItemMergeField.Text = mmValue
                                    End If
                                Next
                            Next
                        End If
                    Next
                Next



Kristian Hyllestad

krhyll
 
Posts: 23
Joined: Fri Nov 11, 2011 12:27 pm

Mon Nov 04, 2013 8:55 am

Hello Kristian,

Thanks for your quick reply.
Sorry for inconvenience. At present we are completing the documentation about the functionality of our product, but if you installed the Spire.Office on computer, you could find these demos in SampleCenter.exe, and you could also find the demos from http://www.e-iceblue.com/Knowledgebase/ ... Merge.html. BTW, your solution is also feasible.

If there are any questions, welcome to get it back to us.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc

cron