• C# winfrom 导出word


             public void ExportWord(string str){

            System.Windows.Forms.SaveFileDialog objSave = new System.Windows.Forms.SaveFileDialog(); objSave.Filter = "(*.doc)|*.doc|" + "(*.*)|*.*";//+ "(*.txt)|*.txt|" objSave.FileName = DateTime.Now.ToString("yyyyMMddHHmm") + ".doc"; if (objSave.ShowDialog() == DialogResult.OK) { Microsoft.Office.Interop.Word.ApplicationClass MyWord = new Microsoft.Office.Interop.Word.ApplicationClass(); Microsoft.Office.Interop.Word.Document MyDoc; Object Nothing = System.Reflection.Missing.Value; MyDoc = MyWord.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); MyDoc.Paragraphs.Last.Range.Font.Name = "宋体"; MyDoc.Paragraphs.Last.Range.Text = this.richTextBox1.Text; object MyFileName = objSave.FileName; //将WordDoc文档对象的内容保存为DOC文档 MyDoc.SaveAs(ref MyFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); //关闭WordDoc文档对象 MyDoc.Close(ref Nothing, ref Nothing, ref Nothing); //关闭WordApp组件对象 MyWord.Quit(ref Nothing, ref Nothing, ref Nothing); MessageBox.Show("文件保存成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //this.txtDetail.SaveFile(objSave.FileName,RichTextBoxStreamType.PlainText); }}
  • 相关阅读:
    考研打卡_Day04
    考研打卡_Day03
    考研打卡-Day02
    吾日三省-归隐
    为什么要写博客?
    用C语言写一个Helloworld_实现第一步编译运行
    C语言中的结构体是怎么定义的_怎么使用?
    C语言的常用的数据类型有哪些_所占字节分别是多少
    Vim编辑器中查找关键词命令_查找与替换命令_多窗口命令
    Vim的基本操作命令与光标移动命令
  • 原文地址:https://www.cnblogs.com/yhyjy/p/2569700.html
Copyright © 2020-2023  润新知