但它在英文操作系统中运行良好。它还为英文 OS 和日文 OS 中的 Excel 和 Power Point 文档返回正确的值。日语操作系统中 Word 文档的页数仅面临问题
我已经尝试了三种类型的代码,但我仍然将总页数设为 1。
参考版本:Microsoft.Office.Interop.Word 版本 15.0.0.0 Visual Studio:2013 Microsoft Office:2016
方法:1:-
Microsoft.Office.Interop.Word.ApplicationClass appWordPageCount = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document DocPageCount = null;
Microsoft.Office.Interop.Word.WdStatistic staticPages = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
object missing = System.Reflection.Missing.Value;
DocPageCount = appWordPageCount.Documents.Open(fileNames);
wordPageCount = DocPageCount.ComputeStatistics(staticPages, ref missing); // fetches page count of word files
方法:2
Microsoft.Office.Interop.Word.Application appWordPageCount = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document DocPageCount = null;
DocPageCount = appWordPageCount.Documents.Open(wordFile);
wordPageCount = DocPageCount.ActiveWindow.ActivePane.Pages.Count;
方法:3
Microsoft.Office.Interop.Word.ApplicationClass appWordPageCount = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document DocPageCount = null;
Microsoft.Office.Interop.Word.WdStatistic staticPages = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
object encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
DocPageCount = appWordPageCount.Documents.Open(ref fileNames, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref encoding, ref missing, ref missing, ref missing, ref missing, ref missing);
wordPageCount = DocPageCount.ComputeStatistics(staticPages, ref missing);
提前感谢您的指导。