没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:胡涛|2023-05-30 11:41:09.560|阅读 164 次
概述:在本文中,我们将演示如何使用Spire.Doc for .NET库在 C# 和 VB.NET 中将上标和下标插入到 Word 中。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式
上标或下标是位于正常文本行上方或下方的字符。它们通常用于科学公式,例如数学方程式或化学表达式。如果您正在创建包含科学公式的文档,您很可能需要插入上标或下标。在本文中,我们将演示如何使用Spire.Doc for .NET库在 C# 和 VB.NET 中将上标和下标插入到 Word 中。
首先,您需要添加包含在 Spire.Doc for.NET 包中的 DLL 文件作为您的 .NET 项目中的引用。DLL 文件可以从此链接下载或通过NuGet安装。
PM> Install-Package Spire.Doc
以下是使用 Spire.Doc for .NET 将上标或下标插入 Word 文档的主要步骤:
【C#】
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; namespace InsertSuperscriptAndSubscript { class Program { static void Main(string[] args) { //Create a Document instance Document document = new Document(); //Load a Word document document.LoadFromFile("Sample.docx"); //Get the first section Section section = document.Sections[0]; //Add a paragraph to the section Paragraph paragraph = section.AddParagraph(); //Add normal text to the paragraph paragraph.AppendText("E = mc"); //Add superscript text to the paragraph TextRange superscriptText = paragraph.AppendText("2"); //Apply superscript formatting to the superscript text superscriptText.CharacterFormat.SubSuperScript = SubSuperScript.SuperScript; //Start a new line paragraph.AppendBreak(BreakType.LineBreak); //Add normal text to the paragraph paragraph.AppendText("H"); //Add subscript text to the paragraph TextRange subscriptText = paragraph.AppendText("2"); //Apply subscript formatting to the subscript text subscriptText.CharacterFormat.SubSuperScript = SubSuperScript.SubScript; //Add normal text to the paragraph paragraph.AppendText("O"); //Set font size for the text in the paragraph foreach (var item in paragraph.Items) { if (item is TextRange) { TextRange textRange = item as TextRange; textRange.CharacterFormat.FontSize = 36f; } } //Save the result document document.SaveToFile("InsertSuperscriptAndSubscript.docx", FileFormat.Docx2013); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Imports Spire.Doc.Fields Namespace InsertSuperscriptAndSubscript Friend Class Program Private Shared Sub Main(ByVal args As String()) 'Create a Document instance Dim document As Document = New Document() 'Load a Word document document.LoadFromFile("Sample.docx") 'Get the first section Dim section As Section = document.Sections(0) 'Add a paragraph to the section Dim paragraph As Paragraph = section.AddParagraph() 'Add normal text to the paragraph paragraph.AppendText("E = mc") 'Add superscript text to the paragraph Dim superscriptText As TextRange = paragraph.AppendText("2") 'Apply superscript formatting to the superscript text superscriptText.CharacterFormat.SubSuperScript = SubSuperScript.SuperScript 'Start a new line paragraph.AppendBreak(BreakType.LineBreak) 'Add normal text to the paragraph paragraph.AppendText("H") 'Add subscript text to the paragraph Dim subscriptText As TextRange = paragraph.AppendText("2") 'Apply subscript formatting to the subscript text subscriptText.CharacterFormat.SubSuperScript = SubSuperScript.SubScript 'Add normal text to the paragraph paragraph.AppendText("O") 'Set font size for the text in the paragraph For Each item In paragraph.Items If TypeOf item Is TextRange Then Dim textRange As TextRange = TryCast(item, TextRange) textRange.CharacterFormat.FontSize = 36F End If Next 'Save the result document document.SaveToFile("InsertSuperscriptAndSubscript.docx", FileFormat.Docx2013) End Sub End Class End Namespace
以上便是在 Word 中插入上标和下标,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询 ;技术交流Q群(767755948)
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
注意: Cogent DataHub 软件 v11 包含一些新功能,您的目标操作系统可能不支持这些功能。
本教程主要为大家介绍如何使用DevExpress WinForms数据网格控件进行数据排序的基础知识,欢迎下载最新版组件体验!
在使用Parasoft C/C++test执行BugDetective数据流分析时,可能会遇到用户自定义的资源API,那在这种情况下,若要判断是否存在资源问题,如资源泄露等,则需要手动配置测试配置。
大型SaaS系统的自动化测试常常受制于界面变化快、结构复杂、加载机制多变等因素。从元素识别到脚本管理,SmartBear TestComplete帮助Salesforce建了可靠的自动化测试体系。
专业的.NET Office套件,涵盖office文档创建、编辑、转换、管理和OCR内容识别等操作
Spire.Doc for .NETSpire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。
Spire.XLS for .NETSpire.XLS for .NET是专业.NET Excel组件,快速完成对Excel各类编程操作
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢