/*
* Created by SharpDevelop.
* User: Administrator
* Date: 2013/9/25
* Time: 22:05
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using Microsoft.Office.Interop.Word;
using Novacode;
namespace DocX01
{
class Program
{
private static Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word. ApplicationClass();
static object oMissing = System.Reflection.Missing.Value;
public static void Main( string[] args)
{
Console. WriteLine( "Hello World!");
int i= GetWordPageCount( @"d:\Spring.docx");
Console. WriteLine(i);
Console. ReadKey( true);
}
public static int GetWordPageCount( string path)
{
try
{
myWordApp.Visible = false;
object filePath = path; //这里是Word文件的路径
//打开文件
Microsoft.Office.Interop.Word.Document myWordDoc = myWordApp.Documents. Open(
ref filePath, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//下面是取得打开文件的页数
int pages = myWordDoc. ComputeStatistics(WdStatistic.wdStatisticPages, ref oMissing);
myWordDoc. Close( ref oMissing, ref oMissing, ref oMissing);
return pages;
}
catch(Exception ex)
{
return 0;
}
}
}
}
* Created by SharpDevelop.
* User: Administrator
* Date: 2013/9/25
* Time: 22:05
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using Microsoft.Office.Interop.Word;
using Novacode;
namespace DocX01
{
class Program
{
private static Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word. ApplicationClass();
static object oMissing = System.Reflection.Missing.Value;
public static void Main( string[] args)
{
Console. WriteLine( "Hello World!");
int i= GetWordPageCount( @"d:\Spring.docx");
Console. WriteLine(i);
Console. ReadKey( true);
}
public static int GetWordPageCount( string path)
{
try
{
myWordApp.Visible = false;
object filePath = path; //这里是Word文件的路径
//打开文件
Microsoft.Office.Interop.Word.Document myWordDoc = myWordApp.Documents. Open(
ref filePath, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//下面是取得打开文件的页数
int pages = myWordDoc. ComputeStatistics(WdStatistic.wdStatisticPages, ref oMissing);
myWordDoc. Close( ref oMissing, ref oMissing, ref oMissing);
return pages;
}
catch(Exception ex)
{
return 0;
}
}
}
}