將 RTF 字符串插入 Word 文檔
Spire.Doc for .NET是一款專門對 Word 文檔進(jìn)行操作的 .NET 類庫。在于幫助開發(fā)人員無需安裝 Microsoft Word情況下,輕松快捷高效地創(chuàng)建、編輯、轉(zhuǎn)換和打印 Microsoft Word 文檔。擁有近10年專業(yè)開發(fā)經(jīng)驗(yàn)Spire系列辦公文檔開發(fā)工具,專注于創(chuàng)建、編輯、轉(zhuǎn)換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團(tuán)隊(duì)研發(fā),不依賴第三方軟件,不受其他國家的技術(shù)或法律法規(guī)限制,同時(shí)適配國產(chǎn)操作系統(tǒng)如中科方德、中標(biāo)麒麟等,兼容國產(chǎn)文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
Spire.Doc for.NET 最新下載
技術(shù)交流Q群(767755948)
RTF 是一種文檔語言,用于對格式化的文本和圖形進(jìn)行編碼,以便在應(yīng)用程序之間輕松傳輸。本文介紹如何使用 Spire.Doc 將一段 RTF 編碼字符串插入 Word 文檔。
第 1 步:初始化 Document 類的一個(gè)實(shí)例,向其中添加一個(gè)部分。
Document doc = new Document(); Section section = doc.
第 2 步:在該部分中添加一個(gè)段落。
Paragraph para = section.AddParagraph();
第 3 步:聲明一個(gè) 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
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網(wǎng)安備
            50010702500608號
渝公網(wǎng)安備
            50010702500608號
             
            
 客服熱線
客服熱線