以编程方式计算 DOCX 文档中具有特定样式的字符/单词/段落的数量

发布于 2024-11-04 03:24:42 字数 174 浏览 0 评论 0原文

我需要以编程方式计算 DOCX 文档中已应用特定已知样式的字符和/或单词和/或段落。

我需要知道 1)这是否可能,以及 2)关于我可以从哪里开始解决这个问题的任何提示。

我熟悉 DOM 导航、XPath/XQuery,并且可以使用 .Net、PHP 或 Java 或任何其他工具,只要我能解决这个问题。

I need to programmatically count the characters and/or words and/or paragraphs which have been applied a specific known style in a DOCX document.

I need to know 1) if this is possible and to 2) any hints as to where I can start to get going to solve this problem.

I am familiar with DOM navigation, XPath/XQuery, and can use .Net, PHP or Java or any other tool as long as I can solve this problem.

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

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

发布评论

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

评论(1

烟织青萝梦 2024-11-11 03:24:42
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();

        try
        {
            object fileName = @"C:\TT\change.docx";
            doc = word.Documents.Open(ref fileName,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing);

            doc.Activate();

            int count = doc.Characters.Count ;
            int words = doc.Words.Count; ;
            int paragraphs = doc.Paragraphs.Count;

            doc.Save();

            doc.Close(ref missing, ref missing, ref missing);
            word.Application.Quit(ref missing, ref missing, ref missing);
        }
        catch (Exception ex)
        {
            doc.Close(ref missing, ref missing, ref missing);
            word.Application.Quit(ref missing, ref missing, ref missing);
        }  
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();

        try
        {
            object fileName = @"C:\TT\change.docx";
            doc = word.Documents.Open(ref fileName,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing);

            doc.Activate();

            int count = doc.Characters.Count ;
            int words = doc.Words.Count; ;
            int paragraphs = doc.Paragraphs.Count;

            doc.Save();

            doc.Close(ref missing, ref missing, ref missing);
            word.Application.Quit(ref missing, ref missing, ref missing);
        }
        catch (Exception ex)
        {
            doc.Close(ref missing, ref missing, ref missing);
            word.Application.Quit(ref missing, ref missing, ref missing);
        }  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文