为什么不能在Word

为什么不能在Word

本文介绍了为什么不能在Word Document 2007的“页眉"和“页脚"部分中添加xml节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Word Document-2007中面临一个奇怪的问题.我已经创建了一个Word文档模板,并且为该模板创建了XML节点以打印重复数据,因为我使用开发人员选项卡"将所有XML节点保留在Word Document上,效果很好.由于该模板创建了6个以上的页面,因此我的客户需要显示页眉和页脚部分.我将XML节点放在Header part部分,但不会打印该节点值.如果我将静态文本放在页眉"部分,则应动态显示,但不能显示.为什么会这样?.

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?.

修改

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>

当我保存文件时,它会保存 Customnode.xsd

when i save the file it save Customnode.xsd

2.然后,我使用Developr标记在Word文档模板中添加了这些自定义节点->添加架构->选择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.

  1. 现在,我已经使用vb.net绑定了数据,如下所示.

  1. 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

推荐答案

谢谢大家给我回复..总之,我终于解决了我的问题...谢谢.

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

这篇关于为什么不能在Word Document 2007的“页眉"和“页脚"部分中添加xml节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 07:49