MS Word文档页数 [英] MS Word Document Page count

查看:100
本文介绍了MS Word文档页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下功能来获取页数,但观察到文件正在打开。实际上我只是通过传递文件来获取页数。



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆