如何在 C# 中打开文件并更改其属性?
我需要打开 Microsoft Word 2003 文件并更改其文件属性。 例如更改摘要选项卡中的主题。
I need to open a Microsoft Word 2003 file and change its file properties. Such as changing the Subject in the Summary Tab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Microsoft 提供了一个非常有用的小程序集,称为 DSOFile。 通过在项目中引用它,您可以修改 Office 文档属性。 它不一定会让您打开实际的 Office 文件的属性对话框,但您当然可以模拟它。
根据微软的说法:
更多详细信息和下载链接可在 http://support.microsoft.com/kb 找到/224351
这是我很久以前使用过的一些(非常古老的)VB 代码的片段。 抱歉,我还没有转换为 C#,并且请注意它是类的一部分,因此存在对实例变量的引用。 尽管如此,它应该很容易理解并满足您自己的需求:
Microsoft provides a very useful little assembly called DSOFile. With a reference to it in your project, you can modify Office document properties. It won't necessarily let you open the actual Office file's properties dialog, but you could certainly simulate it.
According to Microsoft:
More details and a download link can be found at http://support.microsoft.com/kb/224351
Here's a snippet some (very old) VB code I used ages ago. Sorry I haven't converted to C# and be aware that it's part of a class so there are references to instance variables. Still, it should be pretty easy to understand and covert to your own needs:
我可以想到两种方法来做到这一点:
必须在您的
项目,您将需要
主要互操作程序集。
XML 格式并更改该值
XML 文档。 这是MSDN
文档上的文档
特性:
http://msdn.microsoft.com/en-us /library/aa223625(office.11).aspx
如果可以的话,我会选择第二个选项,因为这样您就不必依赖系统上安装的 Word。
I can think of 2 ways to do this:
will have to reference them in your
project, and you will need the
Primary Interop Assemblies.
XML format and change that value in
the XML document. Here is the MSDN
documentation on the document
properties:
http://msdn.microsoft.com/en-us/library/aa223625(office.11).aspx
I would go with the second option if you can, because that way you don't have to depend on Word being installed on the system.