你如何获得主题和主题? Word 文档中的标题(无需打开它)?

发布于 2024-10-25 18:53:37 字数 288 浏览 1 评论 0原文

我想从 Word 文档中读取标题和主题字段,但不想花费启动 Word 来执行此操作的开销。

如果在 Windows 资源管理器中显示标题和主题列,然后导航到其中包含 Word 文档的文件夹,则会显示此信息。使用什么机制来执行此操作(除了 Shell 扩展),因为它速度很快(但我不知道您是否真的需要安装 Word 才能工作),所以我猜它不会启动Word并打开每个文档。

我找到了 Dsofile.dll 的链接,我想我可以使用它,但这适用于 .doc 和 .docx 文件吗?这是唯一的方法吗?

I would like to read the title and subject fields from a Word document, but would rather not have the overhead of firing up Word to do it.

If, in Windows Explorer, I display the title and subject columns, and then navigate to a folder that has Word documents in it, then this information is displayed. What mechanism is being used to do this (aside from Shell extensions) because its fast (but I don't know if you actually need Word installed for this to work), so I'm guessing its not firing up Word and opening each document.

I've found a link to Dsofile.dll, which I presume I could use, but does this work for .doc and .docx files and is it the only way ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┾廆蒐ゝ 2024-11-01 18:53:37

好吧...正如人们可能假设“.doc”文件的时间正在流逝一样,这里是一种从“.docx”文件(或“.xlsx”文件)获取主题和标题的方法事)。

using System;
using System.IO;
using System.IO.Packaging; // Assembly WindowsBase.dll

namespace ConsoleApplication16
{
  class Program
  {
     static void Main(string[] args)
     {
        String path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        String file = Path.Combine(path, "Doc1.docx");

        Package docx = Package.Open(file, FileMode.Open, FileAccess.Read);
        String subject = docx.PackageProperties.Subject;
        String title = docx.PackageProperties.Title;
        docx.Close();
     }
  }
}

我希望这对某人有用。

Well... as one might assume that the time of the ".doc" file is passing, here is one way to get the subject and title from a ".docx" file (or ".xlsx" file for that matter).

using System;
using System.IO;
using System.IO.Packaging; // Assembly WindowsBase.dll

namespace ConsoleApplication16
{
  class Program
  {
     static void Main(string[] args)
     {
        String path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
        String file = Path.Combine(path, "Doc1.docx");

        Package docx = Package.Open(file, FileMode.Open, FileAccess.Read);
        String subject = docx.PackageProperties.Subject;
        String title = docx.PackageProperties.Title;
        docx.Close();
     }
  }
}

I hope this is useful to someone.

星星的軌跡 2024-11-01 18:53:37

您也可以通过 XML 读取它:如何使用 Office 文件格式和架构从 Office 文件中提取信息

这是关于如何以编程方式读取 Word 文档的另一个示例

不管怎样,你必须在某个时刻查看文件内部!

You can read it via XML, too: How to extract information from Office files by using Office file formats and schemas

Here is another example on how to read a Word doc programmatically.

One way or the other you'll have to look inside the file at some point!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文