为什么字数在日语操作系统中总是返回 1



但它在英语操作系统中工作正常。 此外,它还返回英语操作系统以及日语操作系统中的Excel和Powerpoint文档的正确值。 只有问题在日语操作系统中面临Word文档的页数

我已经尝试了三种类型的代码,但仍然我的总页数仅为 1。

参考版本:Microsoft.Office.Interop.Word 版本 15.0.0.0 视觉工作室 : 2013 Microsoft办公室 : 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); 

提前感谢您的指导。

当 Word 应用程序视图模式为"Web 布局"时,它始终返回页数为 1。 其中有三种三种视图模式,读取,打印布局,Web布局。 因此,在获取word文档的页数时,该模式应在"打印布局"中。

相关内容

最新更新