如何从格式文本框Word文档中插入文本

编程入门 行业动态 更新时间:2024-10-28 08:19:27
本文介绍了如何从格式文本框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:

www.microsoft/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文档中插入文本

本文发布于:2023-11-09 09:14:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572001.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   文本   格式   文档   Word

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!