首页  编辑  

取得Word当前文档的页数

Tags: /C#/Office/   Date Created:

// 项目 -> 添加引用 ->COM->Microsoft Word XX.X Object Library

using Microsoft . Office . Interop . Word;

using System . Reflection;

private void button1_Click( object sender , EventArgs e)

{

    ApplicationClass vWordApplication = new ApplicationClass ();

    object vFileName = @"c:\temp\temp.doc" ;

    object vReadOnly = false ;

    object vIsVisible = true ;

    object vMissing = Missing . Value;

    Document vDocument = vWordApplication . Documents . Open(

        ref vFileName,

        ref vMissing, ref vReadOnly, ref vMissing,

        ref vMissing, ref vMissing, ref vMissing,

        ref vMissing, ref vMissing, ref vMissing,

        ref vMissing, ref vIsVisible, ref vMissing,

        ref vMissing, ref vMissing, ref vMissing);

   Text = vWordApplication . Selection . get_Information(

        WdInformation . wdNumberOfPagesInDocument) . ToString();

   vWordApplication . Quit( ref vMissing, ref vMissing, ref vMissing);

}