VB.net讀取Word文檔屬性的辦法。本站提示廣大學習愛好者:(VB.net讀取Word文檔屬性的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是VB.net讀取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的。