添加辉光效果
using IronWord;
using IronWord.Models;

// Create new Word document
WordDocument doc = new WordDocument();

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    GlowEffect = new Glow()
    {
        GlowColor = IronWord.Models.Color.Aqua,
        GlowRadius = 10,
    },
};

// Create paragraph
Paragraph paragraph = new Paragraph();

// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;

// Add run to paragraph
paragraph.AddChild(textRun);

// Add paragraph to document
doc.AddParagraph(paragraph);

// Export new Word document
doc.SaveAs("glowEffect.docx");
NuGet Download
PM > Install-Package IronWord
添加辉光效果

添加辉光效果

为文本添加发光效果

在IronWord中应用发光效果是通过配置TextStyle属性来完成的。 发光效果会在文本周围创建发光边框,可通过自定义颜色和半径属性来控制视觉外观。

要创建一个发光效果,实例化一个TextEffect对象。 GlowRadius来控制效果的扩展。 半径值越高,产生的光晕越分散;半径值越低,产生的光晕越集中。

在配置文本样式后,创建一个包含所需Run。 使用AddChild将样式化的文本添加到段落中,然后将段落添加到文档中。 这遵循文档层次结构:文档 → 段落 → 运行 → 文本内容。

代码解释

上面的代码片段演示了如何创建一个新的 Word 文档并应用带有发光效果的文本样式。 首先,一个新的Word文档被实例化并存储在变量doc中。 然后,创建一个名为TextStyle对象。 此文本样式通过初始化一个特定设置的TextEffect对象配置为包括发光效果。

为了添加带有发光效果的样式文本,首先创建一个Paragraph,然后创建一个包含"Hello World"的TextContent。 Run,应用发光效果。 Paragraph添加到文档中。 这种多步骤方法遵循文档层次结构:文档 → 段落 → 运行 → 文本内容。 最后,Word 文档被导出为一个新文件。

更多示例和演示,请参阅以下文章:如何为文本添加发光效果。

了解更多关于 IronWord 文档元素的信息
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 60,400版本:2026.10刚刚发布