首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

读取Word 的有关问题

2012-03-19 
读取Word 的问题 现在有一个word文档我需要将其中的内容读取出来.voidaa(){Word.ApplicationClasswordnew

读取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();
                }

        }

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


[解决办法]
帮顶!

[解决办法]
UP

热点排行