一聚教程网:一个值得你收藏的教程网站

热门教程

asp.net读取Word文档属性方法

时间:2022-06-25 03:50:48 编辑:袖梨 来源:一聚教程网


'对自定义属性进行读取

 代码如下 复制代码

         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

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

热门栏目