轉(zhuǎn)帖|使用教程|編輯:黃竹雯|2019-02-03 10:03:49.000|閱讀 767 次
概述:Spire.Doc系列教程之在Word中插入上下標(biāo)。使用Spire.Doc時(shí),用戶可以通過CharacterFormat類中SubSuperScript屬性來將字符(串)設(shè)置為上標(biāo)或下標(biāo)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
上下標(biāo)常見于數(shù)學(xué)公式、化學(xué)表達(dá)式等科學(xué)公式中。使用Spire.Doc時(shí),用戶可以通過CharacterFormat類中SubSuperScript屬性來將字符(串)設(shè)置為上標(biāo)或下標(biāo)。
//初始化Document對(duì)象,添加section和段落 Document doc = new Document(); Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); //寫入鈉與水反應(yīng)的化學(xué)反應(yīng)方程式 para.AppendText("2Na+2H"); para.AppendText("2").CharacterFormat.SubSuperScript = SubSuperScript.SubScript;//2作為下標(biāo) para.AppendText("=2NaOH+H"); para.AppendText("2").CharacterFormat.SubSuperScript = SubSuperScript.SubScript;//2作為下標(biāo) para.AppendBreak(BreakType.LineBreak);//換行 //寫入公式a^2+b^2=c^2 para.AppendText("a"); para.AppendText("2").CharacterFormat.SubSuperScript = SubSuperScript.SuperScript;//2作為上標(biāo) para.AppendText("+b"); para.AppendText("2").CharacterFormat.SubSuperScript = SubSuperScript.SuperScript;//2作為上標(biāo) para.AppendText("=c"); para.AppendText("2").CharacterFormat.SubSuperScript = SubSuperScript.SuperScript;//2作為上標(biāo) para.AppendBreak(BreakType.LineBreak);//換行 //寫入公式an=Sn-Sn-1 para.AppendText("an"); para.AppendText("=S"); para.AppendText("n").CharacterFormat.SubSuperScript = SubSuperScript.SubScript;//n作為下標(biāo) para.AppendText("-S"); para.AppendText("n-1").CharacterFormat.SubSuperScript = SubSuperScript.SubScript;//n-1作為下標(biāo) //設(shè)置字體大小 foreach (var i in para.Items) { if (i is TextRange) { (i as TextRange).CharacterFormat.FontSize = 20; } } //保存文檔 doc.SaveToFile("output.docx");
效果圖如下:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn