如何将文本另存为word文件. [英] how to save a text as a word file.

查看:96
本文介绍了如何将文本另存为word文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个多行文本框.我在文本框中写一些文本,然后当我单击按钮事件时,我想将这些文本另存为lappy中选定路径中的word文件(2003、2007等).

Hi, I have a multilined text box. i am writing some text in a text box then when i am clicking on button event then i want to save these text as a word file(2003,2007,etc) in a selected path in my lappy.

推荐答案

亲爱的shrivastava,

Dear shrivastava,

private void button1_Click(object sender, EventArgs e)
      {
          object missing = System.Reflection.Missing.Value;
          object Visible=true;
          object start1 = 0;
          object end1 = 0;

          ApplicationClass WordApp = new ApplicationClass();
          Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
          Range rng = adoc.Range(ref start1, ref missing);

          try
          {
              rng.Font.Name = "Georgia";
         rng.InsertAfter("Hello World!");       // put your text box text here
              object filename = @"D:\MyWord.doc";
              adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
              ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
              WordApp.Visible = true;
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }



为了更好地理解,请检查此链接
http://nishantrana.wordpress.com/2007/11/03/creating -word-document-using-c/ [来自ASP.NET的Microsoft Word文档 [ http://www.c-sharpcorner.com/uploadfile/mahesh/savefiledialog-in -C-Sharp/ [ ^ ]

谢谢



For better understanding check this link
http://nishantrana.wordpress.com/2007/11/03/creating-word-document-using-c/[^]

More about it
Microsoft Word Documents from ASP.NET[^]

File Save(Check this link for better understanding)
http://www.c-sharpcorner.com/uploadfile/mahesh/savefiledialog-in-C-Sharp/[^]

Thanks


使用System.IO导入名称空间
Import namespace using System.IO;
TextWriter tw = new StreamWriter(@"C:\Hello.doc");
tw.WriteLine(Textbox1.Text);
tw.Close();


这篇关于如何将文本另存为word文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆