日期:2014-05-20  浏览次数:20700 次

读取Word 的问题

现在有一个word文档   我需要将其中的内容读取出来.


    void   aa()
        {
                Word.ApplicationClass   word   =   new   Word.ApplicationClass();            
                Word.Documents   docs   =   word.Documents;
                //       打开文件      
                Type   docsType   =   docs.GetType();            
                object   fileName   =   "C:\\Documents   and   Settings\\wen\\桌面\\aa.doc ";
                Word.Document   doc   =   (Word.Document)docsType.InvokeMember( "Open ",
                System.Reflection.BindingFlags.InvokeMethod,   null,   docs,   new   Object[]   {   fileName,   true,   true   });              
                string   fn   =   fileName.ToString();
                Main(fn);                
        }
       
        void   Main(string     FILE_NAME)
        {
                if   (!File.Exists(FILE_NAME))
                {
                        Response.Write( "没有咯! ");
                        return;
                }
                using   (StreamReader   sr   =   File.OpenText(FILE_NAME))          
                {
                        String   input;
                        while   ((input   =   sr.ReadLine())   !=   null)
                        {
                                Response.Write( " ' "   +   input   +   " '+ <br> ");
                        }                      
                        Response.Write( "没有记录了! ");
                        sr.Close();
                }

        }

现在在页面上打印出来的内容和实际相差很大。   出现了乱码.好象把文件头什么的也打印出来了。请大家看看是什么原因.


------解决方案--------------------
帮顶!