如何从c#应用程序插入文本到MS word文档并将其保存为新文件 [英] how to insert text from c# application into MS word document and save it as new file

查看:430
本文介绍了如何从c#应用程序插入文本到MS word文档并将其保存为新文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个桌面应用程序,我需要将文本框的文本保存到一个单词文档中,该文档应由用户创建,文档的位置将由用户选择,然后textbox的值应该被保存在那里。

I have created a desktop application which in that I need to save texts of textbox into into a word document, the document should be created by user and the position of the document would be chosed by user and then the value of textbox should be saved into that.

例如:

这是textBox值

然后有一个保存 按钮,通过点击保存窗口应该打开,然后用户将给它一个名称,并设置其位置,然后点击 最后,文本框的文本将保存到该单词文档中。

then there is a save button, by clicking that the save window should be opened then user will give a name to that and set its position then click OK finally the text of textbox will be saved into that word document.

任何想法如何做?我已经在google中搜索allot,但我找不到任何东西找到方法...

any idea how to do it? I have searched allot in google but I couldn't find anything to find the way ...

推荐答案

对于我自己的问题,我想分享它,如果任何人遇到这种问题,这里是代码:

I have found a solution for my own question, I thought to share it if anyone else has faced this kind of problems, here is the code:

    private void btnSave_Click(object sender, EventArgs e)
    {


        SaveFileDialog saveFileDialog1 = new SaveFileDialog();

        saveFileDialog1.Filter = "Word document|*.doc";
        saveFileDialog1.Title = "Save the Word Document";
        saveFileDialog1.FileName = "MS word document.docx";

        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
        {
            File.WriteAllText(saveFileDialog1.FileName,txtResult.Text.ToString());
        }
    }



这个工作正常,但我想设置font-家庭和字体大小,如果有人知道,请分享您的解决方案?

this works fine, but I want to set font-family and font-size, if anyone knows please share your solution?

这篇关于如何从c#应用程序插入文本到MS word文档并将其保存为新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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