我正在使用Microsoft.Office.Interop.Word计算带空格的字符数,但是当我使用内置函数时,计数它会给我更多的计数,然后从word文档中手动查看。
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
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();
double count = doc.Content.Characters.Count;
所以,这是任何可以直接给空格字符的方法吗?
答案 0 :(得分:1)
试试这个
Microsoft.Office.Interop.Word.Range rng = doc.Content;
rng.Select();
int nb = rng.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticCharactersWithSpaces);