c# - 为什么在日语操作系统中字页数总是返回 1
问题描述
但它在英文操作系统中运行良好。它还为英文 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);
提前感谢您的指导。
解决方案
当 Word 应用程序视图模式为“Web 布局”时,它总是返回页数为 1。其中有三种视图模式,阅读、打印布局、Web 布局。所以在获取word文档的页数时,模式应该是Print Layout。
推荐阅读
- solr - 如何在 Solr 中使用不同的格式化程序突出显示多个单词?
- html - Exce VBA - 从 fetching-builds 网站获取链接
- php - pdf到php中的字节数组转换
- c++11 - ld:未找到体系结构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1
- angular - 通过代理配置从 Electron-Angular 项目调用 API
- python - 为什么 reshape 对 Transpose 的工作方式不同并返回一个新的 nd 数组?
- android - Android的FFmpeg GL转换命令
- ios - 是否可以在文本字段中显示之前修改自动填充字符串?
- ethereum - 如何使用 web3 解码日志并取回事件?
- python - 如何使用 alpha 通道为 png 图像着色?