没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:颜馨|2023-04-18 11:44:11.053|阅读 96 次
概述: 本文介绍如何在 Word 中更改字体颜色,欢迎查阅~
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。
E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式
如果要强调Word文档中的特定段落或文本,可以更改其字体颜色。本文将演示如何在 C# 中更改 Word 中的字体颜色,并使用 Spire.Doc for .NET 库 VB.NET。
首先,您需要将 Spire.Doc for .NET 包中包含的 DLL 文件添加为 .NET 项目中的引用。DLL 文件可以通过 NuGet 安装。
PM> Install-Package Spire.Doc
以下是更改 Word 文档中段落的字体颜色的步骤:
创建文档实例。
【C#】
using Spire.Doc; using Spire.Doc.Documents; using System.Drawing; namespace ChangeFontColorForParagraph { 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]; //Change text color of the first Paragraph Paragraph p1 = section.Paragraphs[0]; ParagraphStyle s1 = new ParagraphStyle(document); s1.Name = "Color1"; s1.CharacterFormat.TextColor = Color.RosyBrown; document.Styles.Add(s1); p1.ApplyStyle(s1.Name); //Change text color of the second Paragraph Paragraph p2 = section.Paragraphs[1]; ParagraphStyle s2 = new ParagraphStyle(document); s2.Name = "Color2"; s2.CharacterFormat.TextColor = Color.DarkBlue; document.Styles.Add(s2); p2.ApplyStyle(s2.Name); //Save the result document document.SaveToFile("ChangeParagraphTextColor.docx", FileFormat.Docx); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Imports System.Drawing Namespace ChangeFontColorForParagraph 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) 'Change text color of the first Paragraph Dim p1 As Paragraph = section.Paragraphs(0) Dim s1 As ParagraphStyle = New ParagraphStyle(document) s1.Name = "Color1" s1.CharacterFormat.TextColor = Color.RosyBrown document.Styles.Add(s1) p1.ApplyStyle(s1.Name) 'Change text color of the second Paragraph Dim p2 As Paragraph = section.Paragraphs(1) Dim s2 As ParagraphStyle = New ParagraphStyle(document) s2.Name = "Color2" s2.CharacterFormat.TextColor = Color.DarkBlue document.Styles.Add(s2) p2.ApplyStyle(s2.Name) 'Save the result document document.SaveToFile("ChangeParagraphTextColor.docx", FileFormat.Docx) End Sub End Class End Namespace
以下是更改 Word 文档中特定文本的字体颜色的步骤:
创建文档实例。
【C#】
using Spire.Doc; using Spire.Doc.Documents; using System.Drawing; namespace ChangeFontColorForText { class Program { static void Main(string[] args) { //Create a Document instance Document document = new Document(); //Load a Word document document.LoadFromFile("Sample.docx"); //Find the text that you want to change font color for TextSelection[] text = document.FindAllString("Spire.Doc for .NET", false, true); //Change the font color for the searched text foreach (TextSelection seletion in text) { seletion.GetAsOneRange().CharacterFormat.TextColor = Color.Red; } //Save the result document document.SaveToFile("ChangeCertainTextColor.docx", FileFormat.Docx); } } }
【VB.NET】
Imports Spire.Doc Imports Spire.Doc.Documents Imports System.Drawing Namespace ChangeFontColorForText 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") 'Find the text that you want to change font color for Dim text As TextSelection() = document.FindAllString("Spire.Doc for .NET", False, True) 'Change the font color for the searched text For Each seletion As TextSelection In text seletion.GetAsOneRange().CharacterFormat.TextColor = Color.Red Next 'Save the result document document.SaveToFile("ChangeCertainTextColor.docx", FileFormat.Docx) End Sub End Class End Namespace
申请临时许可证
如果您想从生成的文档中删除评估消息,或摆脱功能限制,请为自己申请 30 天试用许可证。
以上便是在 Word 中更改字体颜色的教程,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。
欢迎下载|体验更多E-iceblue产品
获取更多信息请咨询 ;技术交流Q群(767755948)
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@wqylolg.cn
CADEditorX是一个ActiveX组件,用于在支持ActiveX和COM技术的任何开发环境中,将CAD功能添加到网页或正在开发的应用程序中。同时可以查看、编辑、转换、打印和测量DWG、DXF、SVG、HPGL、PDF、STEP、IGES、STL和其他CAD文件。
DotNetBrowser 是 TeamDev 开发的商业跨平台.NET 库,基于 Chromium,可将浏览器控件嵌入 Windows Forms 等桌面应用,支持多系统运行。能实现网页展示、DOM 操作、JS 运行等功能,还适用于无头服务器任务,是开发中实现浏览器相关功能的有力工具。
本教程将为大家介绍如何使用MyEclipse的可视化JSF编辑器设计JSP,欢迎下载最新版IDE体验!
在处理 Excel 文件时,除了常见的数据读写操作,有时还需要进一步控制 Excel 文件在打开时的显示状态。本教程将介绍如何使用 Java 和 Spire.XLS for Java 库设置 Excel 文件中的活动工作表和活动单元格。
Spire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。
Spire.Office for .NET专业的.NET Office套件,涵盖office文档创建、编辑、转换、管理和OCR内容识别等操作
Spire.XLS for .NETSpire.XLS for .NET是专业.NET Excel组件,快速完成对Excel各类编程操作
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@wqylolg.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢