翻譯|使用教程|編輯:胡濤|2022-07-21 11:29:56.670|閱讀 204 次
概述:本文將介紹C#如何在Word中插入符號(hào),歡迎查閱!
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
有時(shí)我們需要在段落中插入符號(hào)或特殊字符。文章介紹了用c#代碼在Word中插入符號(hào)的解決方案。在名為 Spire.Doc的Word .NET API的幫助下,我們將使用 ? 和 ? 作為符號(hào)示例來(lái)完成該過(guò)程。
首先我們需要完成準(zhǔn)備工作:
這里是代碼的解釋。
第 1 步:創(chuàng)建 Spire.Doc.Document 的實(shí)例。
Document document = new Document();
第 2 步:添加一個(gè)部分。
Section section = document.AddSection();Section section = document.AddSection();
第 3 步:添加一個(gè)段落。
Paragraph paragraph = section.AddParagraph();
第 4 步:使用 unicode 字符創(chuàng)建符號(hào) ?。
TextRange tr = paragraph.AppendText('\u00c4'.ToString());
其實(shí)下面的step5和step6只是根據(jù)你的需求選擇。
第 5 步:設(shè)置符號(hào) ? 的顏色。
tr.CharacterFormat.TextColor = Color.Red;
第 6 步:添加符號(hào)?。
paragraph.AppendText('\u00cb'.ToString());
第 7 步:保存到 Word 文件。
document.SaveToFile("sample.docx", FileFormat.Docx);
這是完整的代碼:
[C#]
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace InsertSymbol { class Program { static void Main(string[] args) { Document document = new Document(); Section section = document.AddSection(); Paragraph paragraph = section.AddParagraph(); TextRange tr = paragraph.AppendText('\u00c4'.ToString()); tr.CharacterFormat.TextColor = Color.Red; paragraph.AppendText('\u00cb'.ToString()); document.SaveToFile("sample.docx", FileFormat.Docx); } } }
預(yù)覽效果截圖:
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
獲取更多信息請(qǐng)咨詢 ;技術(shù)交流Q群(767755948)
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn