没有合适的资源?快使用搜索试试~ 我知道了~
读取写入前需创建Word的引用,打开文件并获取Word的Document对象。需要说明的一点是,Word自定义属性所能写入的长度是有限制的,约255个字符。
资源推荐
资源详情
资源评论
VB.net读取读取Word文档属性的方法文档属性的方法
读取写入前需创建Word的引用,打开文件并获取Word的Document对象。需要说明的一点是,Word自定义属性
所能写入的长度是有限制的,约255个字符。
复制代码 代码如下:
'对自定义属性进行读取
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的。
资源评论
weixin_38557896
- 粉丝: 0
- 资源: 971
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功