MS Word文档页数 [英] MS Word Document Page count
问题描述
我正在使用以下功能来获取页数,但观察到文件正在打开。实际上我只是通过传递文件来获取页数。
private int getPagecount(string filepath)
{
string MyFileName = filepath;
string execPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly()。CodeBase);
var filePath = Path.Combine(execPath,MyFileName);
Microsoft.Office.Interop.Word.Application app = new Word.Application();
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(filePath);
Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages;
对象缺失= System.Reflection.Missing.Value;
int num = doc.ComputeStatistics(stat,ref missing);
doc .Close();
doc = null;
返回num;
}
预付谢谢。
I'm using following function to get the page count but observed the file is getting opened. Actually I'm trying to get only page count by passing the file.
private int getPagecount(string filepath)
{
string MyFileName = filepath;
string execPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
var filePath = Path.Combine(execPath, MyFileName);
Microsoft.Office.Interop.Word.Application app = new Word.Application();
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(filePath);
Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages;
object missing = System.Reflection.Missing.Value;
int num= doc.ComputeStatistics(stat, ref missing);
doc.Close();
doc = null;
return num;
}
Advance Thanks.
推荐答案
试试这个
Try this
int num= doc.ComputeStatistics(stat, false);
这篇关于MS Word文档页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!