问题
I am facing strange problem in Word Document-2007. I have created a Word Document Template and I create XML nodes for that template to print repeating data, for that I keep all the XML nodes on Word Document using Developer Tab it is working fine. Because that template creates more than 6 pages, my client needs to show the the header and footer section. I put the XML node on Header part section, but it won't print that node value. If I put static text on Header section it should show dynamically, but it doesn't. Why is this?.
Edit
1 . I have create custom xmlnodes like below
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="WorkOrders" elementFormDefault="qualified"
xmlns="http://tempuri.org/XSDSchema1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Cfield1" type="xs:string" />
<xs:element name="Cfield2" type="xs:string" />
</xs:schema>
when i save the file it save Customnode.xsd
2.Than i added these custom nodes in Word document template using Developr tag --> add schema--> select XSD file and then place the Nodes on template.
Now, i have bind the data using vb.net like below.
Dim Traveler As Object Dim Travelerdoc As Object Dim myxmlnode As Object Traveler = CreateObject("Word.Application") Travelerdoc = Traveler.Documents.Add("Documentpath/WordDocument.doc") For Each myxmlnode In Travelerdoc.XMLNodes If myxmlnode.BaseName = "Cfield1" Then myxmlnode.Range.Text ="Hello" If myxmlnode.BaseName = "Cfield2" Then myxmlnode.Range.Text = "Word Document" if(totalrecords<=5) myxmlnode.Range.Select() Travelerdoc.ActiveWindow.Selection.InsertRowsBelow() End If Next
回答1:
Thank you to all for giving reply to me .. anyway finally i resolve my issue ... Thanks.
Here i fallow the solution...
Dim rng As Microsoft.Office.Interop.Word.Range
Dim doc As Microsoft.Office.Interop.Word.Document
Dim headertext As String
For Each wordSection As Microsoft.Office.Interop.Word.Section In Travelerdoc.Sections
rng = wordSection.Headers(Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
rng.Font.Size = 14
rng.InsertAfter(vbTab & vbTab & "WO : " & ds.Tables(0).Rows(0).Item("wo").ToString())
Next
来源:https://stackoverflow.com/questions/17715182/why-cant-i-add-an-xml-node-to-the-header-and-footer-sections-in-word-document-2