Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link to Previous #390

Open
robdplatt opened this issue Nov 13, 2020 · 1 comment
Open

Link to Previous #390

robdplatt opened this issue Nov 13, 2020 · 1 comment

Comments

@robdplatt
Copy link

Is there a way to manually override the Link to Previous flag on a header/footer?

Say we have two documents, both with headers/footers.

Document1
Document2

After inserting a Document2 into a Document1, the header/footer that came from the Document2 is replaced by the last header/footer from Document1.

I know there's an open issue regarding merging documents with different headers/footers. I was hoping to temporarily override the header/footer in the last section. However, because it is Linked to Previous, it ends up removing the header/footer values from the last section of Document1.

Here's a sample of the code I'm trying to run...

        Dim document = Xceed.Words.NET.DocX.Load("")
        document.InsertSectionPageBreak()
        Dim document2 = Xceed.Words.NET.DocX.Load("")
        document.InsertDocument(document2)
        Dim section = document.Sections(document.Sections.Count - 1)
        For Each paragraph In section.Footers.First.Paragraphs
            paragraph.Remove(False)
        Next
        For Each paragraph In section.Footers.Even.Paragraphs
            paragraph.Remove(False)
        Next
        For Each paragraph In section.Footers.Odd.Paragraphs
            paragraph.Remove(False)
        Next

        document.Save()

The footer is successfully removed, but it's also removed from the prior pages where I wish to keep it intact.

@robdplatt
Copy link
Author

I was able to work around this issue by using the following...

            Dim document = Xceed.Words.NET.DocX.Load("")
            document.InsertSectionPageBreak()
            Dim document2 = Xceed.Words.NET.DocX.Load("")
            document.InsertSection()
            document.Sections(document.Sections.Count - 1).AddHeaders()
            document.Sections(document.Sections.Count - 1).AddFooters()
            document.InsertSection() 
            document.InsertDocument(document2)
            document.Save()

I can now attach Document2 to Document1 without Document1 headers/footers appearing at the end of Document1.
This does prevent Document2s headers/footers from showing, which is fine for what I needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant