加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > C语言 > 正文

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

发布时间:2020-12-14 23:55:51 所属栏目:C语言 来源:网络整理
导读:复制代码 代码如下: '对自定义属性进行读取 Dim Properties = SourceDoc.CustomDocumentProperties Dim PropertyType As Type = Properties.GetType Try Dim Authorprop = PropertyType.InvokeMember("Item",Reflection.BindingFlags.Default Or Reflection.

复制代码 代码如下:

'对自定义属性进行读取
         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",Authorprop,New Object() {})

        Catch ex As Exception

        End Try
    '写入 
    Dim Authorprop = PropertyType.InvokeMember("Item",Reflection.BindingFlags.Default Or Reflection.BindingFlags.SetProperty,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的。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读