RT
现在我需要读取一个word文档,还要进行编辑。word里面有几万文字+N多图片,请问怎么可以将word文档(包括字体、图片)读取出来呢?跪求~~~有代码更好啊

解决方案 »

  1.   


     object oFileName = @"C:\3.docx";  //路径,自己修改
                object oReadOnly = true;
                object oMissing = System.Reflection.Missing.Value;            Word._Application oWord;
                Word._Document oDoc;
                oWord = new Word.Application();
                //oWord.Visible = true;//只是为了方便观察
                oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing,
                    ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);            oDoc.ActiveWindow.Selection.WholeStory();
                oDoc.ActiveWindow.Selection.Copy();
                IDataObject data = Clipboard.GetDataObject();
                string mytext = data.GetData(DataFormats.Text).ToString();
                oDoc.Close();            MessageBox.Show(mytext);
      

  2.   

    你这个明显只读取的是文字内容啊,返回string类型的,那图片呢?
      

  3.   

    可以这么写
         /// <summary>
           /// 获取图片路径
           /// </summary>
           /// <param name="bytes"></param>
           /// <returns></returns>
           public static string getSignatureFile(byte[] bytes)
           {   
               string approveFile = Application.StartupPath + @"\temp\" + Guid.NewGuid() + ".bmp";
               if (File.Exists(approveFile))
               {
                   File.Delete(approveFile);
               }
               try
               {
                   Image img = new Bitmap(Image.FromStream(new MemoryStream((byte[])bytes)), 100, 40);
                   img.Save(approveFile, System.Drawing.Imaging.ImageFormat.Bmp);
                   return approveFile;
               }
               catch
               {
                   return "";
               }       }调用
                picture = getSignatureFile((byte[])二进制图片);
      if (!string.IsNullOrEmpty(picture ))
                       {
                           object bookName = "图片";
                           oDoc.Books.get_Item(ref bookName).Select();
                           oWord.Selection.InlineShapes.AddPicture(picture, ref missingValue, ref missingValue, ref missingValue);
                       }
      

  4.   

    http://shudonghe.blog.163.com/blog/static/18533834920113297493390/