如何使用功能"CountNumberOfWordsInWordDocument";计算单词文档中的单词总数 [英] How to use Function "CountNumberOfWordsInWordDocument" to count total number of words in word document
问题描述
你好小组成员,
从本地设备浏览文档并单击上载按钮时,我需要计算单词文档中存在的单词数.我在名称空间下面使用了
Hello Group Members,
I need to count the number of words existed in word document when I browse the document from from my local device and click upload button.I used below name spaces
using Microsoft.Office.Tools.Word;
using CountNumberOfWordsInWordDocument;
当我单击空格按钮时,我得到的功能是"CountNumberOfWordsInWordDocument".我想知道如何通过函数"CountNumberOfWordsInWordDocument"使用此函数获取Word文档中的单词数.
When I click space button I am getting function as "CountNumberOfWordsInWordDocument" . I want to know how can I use this function to get number of words in word document by using the function "CountNumberOfWordsInWordDocument".
推荐答案
可以尝试这种方法吗? br/>
Can you try this alternative?
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:\worddocument.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 words = doc.Words.Count;
// update list/object where you want to store word count
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);
}
您可能需要将相关引用添加到Word Interop DLL.
检查并回复!
You might need to add relevant references to Word Interop DLLs.
Check and do reply!
这篇关于如何使用功能"CountNumberOfWordsInWordDocument";计算单词文档中的单词总数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!