如何从格式文本框Word文档中插入文本 [英] How to insert text in to a word document from Rich Text Box

查看:304
本文介绍了如何从格式文本框Word文档中插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的C#应用​​程序丰富的文本框,它包含不同的行文本(一对多行)。我想获得这些行,并将其插入到Word文档的字体和我想要的字体大小。这是它应该是什么样子。

I have a rich text box in my c# application and it contains different lines of text(one to many lines). I want to get those lines and insert it to a Word document with the font and the font size I want. This is how it should look like.

意见:

      
  • 1号线从丰富的文本框
  •   
  • 2号线从丰富的文本框
  •   
  • 3号线从丰富的文本框
  •   
  • Line 1 from the rich text box
  • Line 2 from the rich text box
  • Line 3 from the rich text box

我希望这种情况发生通过互操作库。

I want this to happen by using interop library.

我需要一些示例code这个,因为我是一个新手

I need some sample code for this since I'm a newbie

推荐答案

您可以使用OpenXML的SDK包:

You could use the OpenXML SDK Package:

http://www.microsoft.com/en-我们/下载/ details.aspx?ID = 5124

然后像做了以下内容:

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;

const string fileName = @"C:\YourFile.docx";
string dataToInsert = txtYourRichTextBox.Text;

using (var document = WordprocessingDocument.Open(fileName, true))
{
   var doc = document.MainDocumentPart.Document;
   document.Body.Append(dataToInsert);
   document.Save();
}

这篇关于如何从格式文本框Word文档中插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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