Word控件Spire.Doc 【脚注】字体(2): 在C#, VB.NET中设置Word字体

Spire.Doc for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处理,小巧便捷。 

E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Word 字体设置允许用户更改文档中的文本字体样式和大小。通过精彩的字体设置,文档布局和外观将更具吸引力。更重要的是,为了使一些特殊的单词,短语或段落更加明显,用户可以设置不同的字体样式或大小。例如,标题通常设置为不同的字体样式,与正文的大小更大。

Spire.Doc for .NET是一个专业的.NET Word组件,使用户可以在Word文档中设置字体。本指南将展示如何通过Spire.Doc for .NET使用C#、VB.NET进行设置,以下是设置后的屏幕截图。

  • 加载文档并获取要设置字体的段落。
  • 然后,声明新的段落样式并设置此样式的“字体名称”和“字体大小”属性。
  • 最后,应用段落样式并保存文档。代码如下:

[C#]

using Spire.Doc;
using Spire.Doc.Documents;

namespace WordImage
{
class ImageinWord
{
static void Main(string[] args)
{
//Load Document
Document document = new Document();
document.LoadFromFile(@"E:\Work\Documents\WordDocuments\Humor Them.docx");

//Get Paragraph
Section s = document.Sections[0];
Paragraph p = s.Paragraphs[1];

//Set Font Style and Size
ParagraphStyle style = new ParagraphStyle(document);
style.Name = "FontStyle";
style.CharacterFormat.FontName = "Century Gothic";
style.CharacterFormat.FontSize = 20;
document.Styles.Add(style);
p.ApplyStyle(style.Name);

//Save and Launch
document.SaveToFile("font.docx", FileFormat.Docx2010);
System.Diagnostics.Process.Start("font.docx");
}
}
}

[VB.NET]

Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordImage
Friend Class ImageinWord
Shared Sub Main(ByVal args() As String)
'Load Document
Dim document As New Document()
document.LoadFromFile("E:\Work\Documents\WordDocuments\Humor Them.docx")

'Get Paragraph
Dim s As Section = document.Sections(0)
Dim p As Paragraph = s.Paragraphs(1)

'Set Font Style and Size
Dim style As New ParagraphStyle(document)
style.Name = "FontStyle"
style.CharacterFormat.FontName = "Century Gothic"
style.CharacterFormat.FontSize = 20
document.Styles.Add(style)
p.ApplyStyle(style.Name)

'Save and Launch
document.SaveToFile("font.docx", FileFormat.Docx2010)
System.Diagnostics.Process.Start("font.docx")
End Sub
End Class
End Namespace

Spire.Doc是一个专业的Word组件,可用于生成、加载、编写、编辑和保存.NET、Silverlight和WPF的Word文档。

以上便是如何在C#, VB.NET中设置Word字体的教程,如果您有其他问题也可以继续浏览本系列文章,获取相关教程

猜你喜欢

转载自blog.csdn.net/m0_67129275/article/details/130399161