• 您的位置我爱Aspx >> VC.Net >> 从 VBA 中使用 Visual Basic .NET 将 Word 文档序列化为 XML
  • 从 VBA 中使用 Visual Basic .NET 将 Word 文档序列化为 XML

  • 作者:aspxer  来源:internet  日期:2007-5-21 23:49:28  关键字:.net,xml
  • 构造函数的参数)以及 Serialize 函数所需的许多其他值。

    Dim specDoc As Document Dim writer As XmlTextWriter imlFilePathName = specDoc.Path & "\" & _ specDocConvertedName.Replace(specDoc.Name, ".xml") writer = New XmlTextWriter(imlFilePathName, Nothing) 程序列表 4:将 Word 文档链接到 Visual Basic .NET 程序

    序列化层次结构表

    谈到我是如何使用托管 XML 大大提高(提高几乎 60 倍)XML 应用程序的性能时,我想我应该向您介绍几种我在实际序列化 Word 内容时使用的技术。

    因此,下面为您介绍我是如何使用 Word 表模拟嵌套的层次结构,以及如何将该表序列化为 XML 的。查看示例 WordXml.Net 测试规范(在源代码下载中),您会发现 Set 1 使用两个类实现测试安装和清除过程。规范的 Context 表中的第二行是缩进的。以下用于序列化 Context 表的源代码将查找这些缩进以便嵌套 XML 元素:

    writer.WriteStartElement("contextSection", NSURI_IML) Do While True rng = rng.Next(WdUnits.wdParagraph) If rng.Tables.Count = 0 Then If Len(rngTextString) > 0 Then writer.WriteElementString("p", rngTextString) End If Else thisTable = rng.Tables.Item(FLD_CONTEXT_CLS) writer.WriteStartElement("grp") For intCt = 3 To thisTable.Rows.Count ´ 获取当前 Group 类名和 Set 列表 cellName = _ thisTable.Rows.Item(intCt).Cells.Item(FLD_CONTEXT_CLS) cellSets = _ thisTable.Rows.Item(intCt).Cells.Item(FLD_CONTEXT_SETS) If thisTable.Rows.Item(intCt).IsLast Then nextLeftIndent = 0 Else nextLeftIndent = _ thisTable.Rows.Item(intCt + _ 1).Cells.Item(FLD_CONTEXT_CLS). _ Range.Paragraphs.LeftIndent End If ´ 如果 intLIndent > 0,则为子行 leftIndent = cellName.Range.Paragraphs.LeftIndent writer.WriteStartElement("grp", NSURI_CONTEXT) writer.WriteAttributeString( _ "cls", _ cleanCell.Match(cellName.Range.Text).Value) ´ 使用空格分隔 Set 值 setList = Split(cleanCell.Match(cellSets.Range.Text).Value) ´ 为每个引用的 Set 添加一个 varref 子项 For Each setRef In setList If "" <> setRef Then writer.WriteStartElement("varref", NSURI_CONTEXT) writer.WriteAttributeString("set", Trim(setRef)) writer.WriteEndElement() End If Next setRef If nextLeftIndent = leftIndent Then ´ 结束当前 grp writer.WriteEndElement() ElseIf nextLeftIndent < leftIndent Then ´ 结束当前 grp writer.WriteEndElement() ´ 结束父 grp writer.WriteEndElement() End If Next intCt ´ 结束包含的 grp 标记 writer.WriteEndElement() Exit Do End If ´ rng.Tables.Count = 0 Loop ´ 结束 contextSection 标记 writer.WriteEndElement() 程序列表 5:序列化 NewTestSpec.doc 中的 Context 表我对这篇文章有话说?

  • 广告位招租,广告代号:content_468_15
  • 上一篇:SCO UNIX 下设备驱动程序开发
    下一篇:mfc版本及其对应vc版本一览表