获取Word文档的作者和主题
时间:2023-12-11 20:24:19
当然要先添加对Word的组件的引用,添加命名空间的引用,代码:
Word.Application oWord;
Word._Document oDoc;
object oMissing = Missing.Value;
object docBuiltInProps;
object Source = @"DocPath";
object Unknown =Type.Missing;
oWord = new Word.Application();
try
{
oDoc = oWord.Documents.Open(ref Source,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown,ref Unknown,ref Unknown,
ref Unknown );
docBuiltInProps = oDoc.BuiltInDocumentProperties;
Type typeDocBuiltInProps = docBuiltInProps.GetType();
//获取作者
string index = "Author";
string propsValue;
object docAuthor = typeDocBuiltInProps.InvokeMember("Item",
BindingFlags.Default |
BindingFlags.GetProperty,
null,docBuiltInProps,
new object[] {index} );
Type typeDocAuthorProp = docAuthor.GetType();
propsValue = typeDocAuthorProp.InvokeMember("Value",
BindingFlags.Default |
BindingFlags.GetProperty,
null,docAuthor,
new object[] {} ).ToString();
MessageBox.Show( propsValue,"Author" );
//获取主题
index = "Subject";
propsValue = "The Subject";
object docSubjectProp = typeDocBuiltInProps.InvokeMember("Item",
BindingFlags.Default |
BindingFlags.GetProperty,
null,docBuiltInProps,
new object[] {index} );
Type typeDocSubjectProp = docSubjectProp.GetType();
propsValue = typeDocSubjectProp.InvokeMember("Value",
BindingFlags.Default |BindingFlags.GetProperty,
null,docSubjectProp,
new object[] {} ).ToString();
MessageBox.Show( propsValue,"Subject" );
}
finally
{
//关闭word进程
object save = false;
oWord.Quit(ref save,ref Unknown,ref Unknown);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord);
}
,办公群:185219299
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
ppt文本框根据文字自动调整大小怎么设置?
![](https://img.aspxhome.com/file/2023/30/a264003_0s.jpg)
让你成为Word软件编辑高手的10条技巧
excel表格中的实验数据怎么进行曲线拟合?
![](https://img.aspxhome.com/file/2023/5/40535_0s.jpg)
Win7系统msconfig命令提示找不到怎么办?一招教你简单修复
![](https://img.aspxhome.com/file/2023/27/a229941_0s.jpg)
excel表格输入长数字出现乱码怎么办
如何删除word文字自带的背景色?
Win7系统添加新输入法选项的操作方法
![](https://img.aspxhome.com/file/2023/2/a284641_0s.jpg)
win7存储路径怎么更改?win7存储路径更改教程
![](https://img.aspxhome.com/file/2023/30/a269579_0s.jpg)
在wps表格中如何为表格添加边框
配合路由器设置电脑静态ip方法图文教程
![](https://img.aspxhome.com/file/2023/29/a251473_0s.jpg)
win10分辨率设置?win10分辨率怎么调?
![](https://img.aspxhome.com/file/2023/9/47129_0s.jpg)
如何操作excel求总和的教程
wps表格怎么打印证件照 wps表格打印证件照的方法
![](https://img.aspxhome.com/file/2023/0/a165790_0s.jpg)
WPS Word文档如何批量删除空格
![](https://img.aspxhome.com/file/2023/8/a185958_0s.jpg)
word表格跳页怎么处理
![](https://img.aspxhome.com/file/2023/2/35052_0s.png)
win10怎么查看电脑性能评分?
![](https://img.aspxhome.com/file/2023/30/a265788_0s.jpg)
Win10系统下全屏运行穿越火线的方法
![](https://img.aspxhome.com/file/2023/5/a314627_0s.jpg)
word文档如何删除作者信息
![](https://img.aspxhome.com/file/2023/9/31619_0s.png)
excel 条件格式整行变色的设置规则和操作步骤介绍
![](https://img.aspxhome.com/file/2023/4/a155094_0s.gif)
Win11使用CAD卡顿或者致命错误怎么办?Win11无法正常使用CAD的解决方法
![](https://img.aspxhome.com/file/2023/27/a235072_0s.png)