Word控件Spire.Doc 【段落处理】教程(十三):如何在 C#、VB.NET 中将 RTF 字符串插入 Word 文档

第 1 步:初始化 Document 类的一个实例,向其中添加一个部分。

Document doc = new Document();Section section = doc.

第 2 步:在该部分中添加一个段落。

Paragraph para = section.AddParagraph();

第 3 步:声明一个 String 变量来存储 RTF 字符串。

String rtfString = @"{rtf1ansideff0 {fonttbl {f0 hakuyoxingshu7000;}}f0fs28 Hello, World}";

第 4 步:将 RTF 字符串附加到段落。

para.AppendRTF(rtfString);

第 5 步:保存文件。

doc.SaveToFile("Output.docx");

输出

How to Insert RTF String to Word Documents in C#, VB.NET

完整代码

[C#]

using Spire.Doc;using Spire.Doc.Documents;using System;namespace InsertRTF{class Program{static void Main(string[] args){Document doc = new Document();Section section = doc.AddSection();Paragraph para = section.AddParagraph();String rtfString = @"{rtf1ansideff0 {fonttbl {f0 hakuyoxingshu7000;}}f0fs28 Hello, World}";para.AppendRTF(rtfString);doc.SaveToFile("Output.docx");}}}

[VB.NET]

Imports Spire.DocImports Spire.Doc.DocumentsNamespace InsertRTFClass ProgramPrivate Shared Sub Main(args As String())Dim doc As New Document()Dim section As Section = doc.AddSection()Dim para As Paragraph = section.AddParagraph()Dim rtfString As [String] = "{rtf1ansideff0 {fonttbl {f0 hakuyoxingshu7000;}}f0fs28 Hello, World}"para.AppendRTF(rtfString)doc.SaveToFile("Output.docx")End SubEnd ClassEnd Namespace

欢迎下载|体验更多E-iceblue产品

如需获取更多产品相关信息请咨询在线客服  


标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年4月20日
下一篇 2022年4月20日

相关推荐

发表回复

登录后才能评论