翻譯|使用教程|編輯:胡濤|2022-05-24 11:40:11.133|閱讀 222 次
概述:本文介紹如何使用 Spire.Doc 將一段 RTF 編碼字符串插入 Word 文檔。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
RTF 是一種文檔語言,用于對格式化的文本和圖形進行編碼,以便在應用程序之間輕松傳輸。本文介紹如何使用 Spire.Doc 將一段 RTF 編碼字符串插入 Word 文檔。
第 1 步:初始化 Document 類的一個實例,向其中添加一個部分。
Document doc = new Document(); Section section = doc.
第 2 步:在該部分中添加一個段落。
Paragraph para = section.AddParagraph();
第 3 步:聲明一個 String 變量來存儲 RTF 字符串。
String rtfString = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 hakuyoxingshu7000;}}\f0\fs28 Hello, World}";
第 4 步:將 RTF 字符串附加到段落。
para.AppendRTF(rtfString);
第 5 步:保存文件。
doc.SaveToFile("Output.docx");
輸出:
完整代碼:
[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 = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 hakuyoxingshu7000;}}\f0\fs28 Hello, World}";
para.AppendRTF(rtfString);
doc.SaveToFile("Output.docx");
}
}
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Documents
Namespace InsertRTF
Class Program
Private 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] = "{\rtf1\ansi\deff0 {\fonttbl {\f0 hakuyoxingshu7000;}}\f0\fs28 Hello, World}"
para.AppendRTF(rtfString)
doc.SaveToFile("Output.docx")
End Sub
End Class
End Namespace
歡迎下載|體驗更多E-iceblue產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn