如何用C#将word文档读取到richtextbox中,并保存到word中?

解决方案 »

  1.   


    string fileName = Request.PhysicalApplicationPath.ToString() + this.filepath.Replace(@"\", @"\\") + @"mm\" + this.ddlType.SelectedValue + ".htm";//路径
      FileStream fs = new FileStream(@fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);//如果文件不存在的话,新建一个。存在的话,直接写入。
      StreamWriter writer = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
      writer.WriteLine(HttpUtility.HtmlDecode(this.txtContent.Text.Trim()));
      writer.Close();
      this.Page.RegisterStartupScript("alert", "<script language=javascript>alert('操作完成!');</script>");
      

  2.   

    先把word文档装成RTF格式后
    richTextBox.LoadFile(strFileName,RichTextBoxStreamType.PlainText)
    Word.ApplicationClass wordApp=new ApplicationClass();
    object file=path;
    object nullobj=System.Reflection.Missing.Value;   
    Word.Document doc = wordApp.Documents.Open(
    ref file, ref nullobj, ref nullobj,   
    ref nullobj, ref nullobj, ref nullobj,   
    ref nullobj, ref nullobj, ref nullobj,   
    ref nullobj, ref nullobj, ref nullobj);doc.ActiveWindow.Selection.WholeStory();
    doc.ActiveWindow.Selection.Copy();
    IDataObject data=Clipboard.GetDataObject();
    string str=data.GetData(DataFormats.Text).ToString();
    doc.Close();