如何取得word,excel,ppt文档的页数?

wangxt 2009-03-27 06:26:46
需要查出某目录下所有文档的页数,请问如何取得word,excel,ppt文档的页数?
...全文
416 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shenjigong19801109 2009-12-20
  • 打赏
  • 举报
回复
s
wangxt 2009-03-31
  • 打赏
  • 举报
回复
谢谢各位相助,已经解决了读WORD,EXCEL,PPT的问题,不过这样就为了统计一个页数而一个一个的打开文件有点慢,不知道还有什么更快的方法,不用OFFICE程序去打开文件,直接读一下就可以的?
ysd_xwl 2009-03-27
  • 打赏
  • 举报
回复
值得学习!谢谢高人!
zzyzgydotnet 2009-03-27
  • 打赏
  • 举报
回复
teerhu 2009-03-27
  • 打赏
  • 举报
回复
学习
fanbo 2009-03-27
  • 打赏
  • 举报
回复
楼上牛人。
cppfaq 2009-03-27
  • 打赏
  • 举报
回复
To count the pages in MSWord document, we need to follow following steps:

1 Create an object of Word Application.
2 Open the required Word document using the open() function of Documents collection of Word document. This function returns the Word.Document object.
3 Cal the ComputeStatistics fumction on Word.Document object passing it an enum WdStatistic with value equal to wdStatisticPages. This function will return the number of pages in the opened word document.

class PageCounter 
{
/// <SUMMARY>
/// The main entry point for the application.
/// </SUMMARY>
[STAThread]
static void Main(string[] args)
{
Word.ApplicationClass WordApp = new Word.ApplicationClass();

// give any file name of your choice.
object fileName = "D:\\abc\\oop1.doc";
object readOnly = false;
object isVisible = true;

// the way to handle parameters you don't care about in .NET
object missing = System.Reflection.Missing.Value;

// Make word visible, so you can see what's happening
//WordApp.Visible = true;
// Open the document that was chosen by the dialog
Word.Document aDoc = WordApp.Documents.Open(ref fileName,
ref missing,ref readOnly, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing,
ref missing, ref isVisible);

Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages ;
int num = aDoc.ComputeStatistics(stat,ref missing);
System.Console.WriteLine ("The number of pages in doc is {0}",
num);
System.Console.ReadLine();
}
}
sunshine_anycall 2009-03-27
  • 打赏
  • 举报
回复
能不能具体说说
什么条件下需要获取页数

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧