读取Word文档属性 VB.net读取Word文档属性的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

读取Word文档属性 VB.net读取Word文档属性的方法

  2021-03-18 我要评论
想了解VB.net读取Word文档属性的方法的相关内容吗,在本文为您仔细讲解读取Word文档属性的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:读取Word,下面大家一起来学习吧。

复制代码 代码如下:

'对自定义属性进行读取
         Dim Properties = SourceDoc.CustomDocumentProperties
            Dim PropertyType As Type = Properties.GetType

        Try
            Dim Authorprop = PropertyType.InvokeMember("Item", Reflection.BindingFlags.Default Or Reflection.BindingFlags.GetProperty, Nothing, Properties, New Object() {"备注"})
            ResultString = Authorprop.GetType.InvokeMember("Value", Reflection.BindingFlags.Default Or Reflection.BindingFlags.GetProperty, Nothing, Authorprop, New Object() {})

        Catch ex As Exception

        End Try
    '写入 
    Dim Authorprop = PropertyType.InvokeMember("Item", Reflection.BindingFlags.Default Or Reflection.BindingFlags.SetProperty, Nothing, properties, New Object() {"备注", ResultString})

另一种写法:

复制代码 代码如下:

'增加新属性
SourceDoc.CustomDocumentProperties.Add(Name := "PropertyName", LinkToContent := False, Type := Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, Value := "PropertyValue")

'修改属性
SourceDoc.CustomDocumentProperties("PropertyName").Value = PropertyValue

'获取属性值
PropertyValue =SourceDoc.CustomDocumentProperties("PropertyName").Value

复制代码 代码如下:

'读取内置属性,以备注为例
 ResultString= SourceDoc.BuiltInDocumentProperties(Microsoft.Office.Interop.Word.WdBuiltInProperty.wdPropertyComments).value

读取写入操作后可以通过在Word文档上右键->属性查看效果,但当Word文档处于打开状态时,文档上右键是没有“自定义”和“摘要”这两个Tab的。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们