没有人啊???自己顶下啊!!!!! string strA = new StreamReader(@"d:\test.doc", Encoding.UTF8).ReadToEnd();//a.txt内容
这行代码为什么能够获取txt的内容但是对于DOC的内容显示的就是乱码啊?

解决方案 »

  1.   

    1. 直接使用wpf的浏览器控件
    2.使用DSOFramer(虽然有点老,但是今天看来还是挺适用的,只是最新版本的无法支持而已,我做过支持的2010)
    3.自己用stream来读取。按格式写 ,或者使用flowdocument这样的文档对象
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using Word = Microsoft.Office.Interop.Word;
    using System.IO;
    namespace wordOpen1
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }        private void Button_Click(object sender, RoutedEventArgs e)
            {
                //Word.Application opd = new Microsoft.Office.Interop.Word.Application();
                //Microsoft.Office.Interop.Word.Document doc = opd.Documents.Open(FileName: Path.Combine(_AppDomain.CurrentDomain.BaseDirectory,));
                
                try  
                {  
                    Word.Application app = new Microsoft.Office.Interop.Word.Application();  
                    Word.Document doc = null;  
                    object unknow = Type.Missing;  
                    //app.Visible = true;  
                    string str = @"D:\test.doc";  
                    object file = str;  
                    doc = app.Documents.Open(ref file,  
                        ref unknow, ref unknow, ref unknow, ref unknow,  
                        ref unknow, ref unknow, ref unknow, ref unknow,  
                        ref unknow, ref unknow, ref unknow, ref unknow,  
                        ref unknow, ref unknow, ref unknow);  
                    //string temp = doc.Paragraphs[2].Range.Text.Trim();
                    string temp = doc.Content.Text.Trim();
                    testBox1.Text = temp;
                    
                }  
                catch (Exception ex)  
                {  
                   MessageBox.Show(ex.Message);  
                }  
               
               
              
             }  
                 
            }
        
    }用这代码调试之后虽然可以显示出word文档的内容但是还是会有问题!!