打开.doc后,如何识别出文档的标题?

解决方案 »

  1.   

    using System;
    using Excel=Microsoft.Office.Interop.Excel;
    using Word = Microsoft.Office.Interop.Word;
    namespace ctrexecel
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    class Class1
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    object opt = System.Reflection.Missing.Value;
    Word.Application app = new Word.ApplicationClass();
    string strfile = "c:\\1.doc";
    object file = strfile;
    app.Documents.Open( ref file , ref opt , ref opt , ref opt , ref opt ,ref opt , ref opt ,ref  opt,
                  ref opt , ref opt , ref opt , ref  opt , ref  opt , ref  opt, ref  opt , ref opt );
    app.Visible = true;
    Word.Document doc = app.ActiveDocument;
    for( int i=1 ; i<=doc.Paragraphs.Count ; i++)
    {
    Word.Paragraph pg = doc.Paragraphs[i];
    Word.Style style = (Word.Style)pg.get_Style();
    string strstyle = style.NameLocal;
    System.Console.WriteLine( strstyle);//如果strtyle="标题1"就是标题


    }
    app.Quit( ref opt , ref opt , ref opt  );

    }
    }
    }
    office2003 + vs.net