欢迎来到工商注册核名查询系统!

vb

当前位置:主页 > 软件编程 > vb >

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

来源:本站原创|时间:2022-11-25|栏目:vb|

复制代码 代码如下:

'对自定义属性进行读取
         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的。

更多vb

您可能感兴趣的文章

阅读排行

本栏相关

随机阅读

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 工商注册核名查询系统 版权所有