Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

Headers and footers not saved in XML format

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Haydn - 12 Sep 2005 11:47 GMT
I've inserted some text into a Word document using the
wordApplication.Selection.InsertXML() method.  Then I've added headers and
footers as follows (this.document is the active document):

HeaderFooter header =
this.document.Sections.First.Headers[WdHeaderFooterIndex.wdHeaderFooterFirstPage];
HeaderFooter footer =
this.document.Sections.First.Footers[WdHeaderFooterIndex.wdHeaderFooterFirstPage];

// Clear any text in there.
header.Range.Delete(ref missing, ref missing);
footer.Range.Delete(ref missing, ref missing);

// Insert header and footer.
header.Range.InsertXML(this.resourceManager.GetString("HeaderXml",
CultureInfo.CurrentCulture), ref dummy);
footer.Range.InsertXML(this.resourceManager.GetString("FooterXml",
CultureInfo.CurrentCulture), ref dummy);

// Ensure different header and footer on first page.
this.document.Content.PageSetup.DifferentFirstPageHeaderFooter = -1;
// Ensure header is visible.
this.document.ActiveWindow.View.SeekView = WdSeekView.wdSeekFirstPageHeader;
this.document.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;

Now, the HeaderXML and footerXML strings simply contain a <w:tbl> element.

In some circumstances, after I've inserted the main text into the document,
Word adds a section break of its own (continuous).

Whilst this still displays everything ok, Word does not save properly.  If I
save the document in XML format (no transforms, etc), the header and footer
is not saved out.  However, if I save the same document in Word Document
(DOC) format, the header and footer is saved out.

Also, if Word does not add a section break of its own when I insert the text
into the main document, the header and footer is saved in both XML and DOC
format.

It seems that for some reason the code I have for inserting headers and
footers causes them not to be saved out if and only if, Word inserts its own
section breaks when I insert text.

Can someone please help as I have to sort this ASAP?

Thanks.

Haydn
Haydn - 12 Sep 2005 15:34 GMT
Found the problem.  Looks like I had embedded paragraphs.  The original XML
in the document was like:

<w:p>
 <myelement>...</myelement>
</w:p>

Then after the transform, it would look like:

<w:p>
   <w:p>
        ...
   </w:p>
</w:p>

Guess the only way Word could handle this was to insert a section break.  
All is well once more.

> I've inserted some text into a Word document using the
> wordApplication.Selection.InsertXML() method.  Then I've added headers and
[quoted text clipped - 44 lines]
>
> Haydn
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.