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 Dec 30, 2017 4:57 pm

hello
i have to merge file heder.doc and footer.rtf file content in my template document before start mailmerge fonction.

the logic in word
open file header.doc (only data header in this file)
select all <Crtl+A> and copy <Crtl+C> all data of file
open current model mailmerge
<Crtl+V> paste all data in header section
close
ans same process for footer

i had made this code but sometime there is paragraph is empty and insert cRLF in header modele
have you a better solution ?
tank's
fred

Code: Select all
HAndF = section.HeadersFooters.Footer 'template
        Using foot As New Document()
            foot.LoadFromFile(My.Settings.RepSource & Nom2fichier & GLB_const.ext_piedepage, FileFormat.Docx2013)
'remove template header paragraph           
 For Each p As Paragraph In HAndF.Paragraphs()
                HAndF.Paragraphs.Remove(p)
            Next
            For Each p As Paragraph In foot.Sections(0).Paragraphs
                HAndF.Paragraphs.Insert(HAndF.Paragraphs.Count(), p.Clone())
            Next
        End Using

labaffagaston
 
Posts: 42
Joined: Sun Dec 24, 2017 7:38 pm

Mon Jan 01, 2018 3:47 am

Hello,

Thanks for your inquiry. The method you were using is best, and when there is empty paragraph, you could delete it and then insert. Here are some code segments for your reference.
Code: Select all
 For Each p As Paragraph In foot.Sections(0).Paragraphs
                If p.ChildObjects.Count <> 0 Then
                    HAndF.Paragraphs.Insert(HAndF.Paragraphs.Count(), p.Clone())
                End If
            Next

Sincerely,
Gary
E-iceblue support team
User avatar

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

Thu Jan 04, 2018 9:34 am

Hello,

Has your issue get resolved?
Thanks in advance for your valuable feedback and time.

Sincerely,
Gary
E-iceblue support team
User avatar

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

Return to Spire.Doc