彩票走势图

国产PPT格式控件Spire.Presentation功能演示:添加多行多列文本水印至PPT文档

翻译|使用教程|编辑:李显亮|2021-02-24 10:59:57.787|阅读 255 次

概述:本文将详细介绍如何使用C# 、VB.NET给PowerPoint文档添加多行多列文本水印。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

Spire.Presentation for .NET 是专业的 PowerPoint组件,开发者可以在 .NET 平台上对 PPT文档进行生成、修改、转换和打印等操作,而无需安装 Microsoft PowerPoint。

本文将详细介绍如何使用C# 、VB.NET给PowerPoint文档添加多行多列文本水印。可点击此处下载最新版测试。

这么优秀的国产工具怎能错过呢!想要获取更多福利的朋友哦~


C#

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WatermarkDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载示例文档
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("Sample.pptx");

            //获取文本的大小
            Font font = new Font("宋体", 20);
            String watermarkText = "冰蓝科技";
            SizeF size = TextRenderer.MeasureText("E-iceblue", font);
            float x = 30;
            float y = 80;
            for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { //绘制文本,设置文本格式并将其添加到第一张幻灯片 RectangleF rect = new RectangleF(x, y, size.Width, size.Height); IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect); shape.Fill.FillType = FillFormatType.None; shape.ShapeStyle.LineColor.Color = Color.White; shape.Rotation = -45; shape.Locking.SelectionProtection = true; shape.Line.FillType = FillFormatType.None; shape.TextFrame.Text = watermarkText; TextRange textRange = shape.TextFrame.TextRange; textRange.Fill.FillType = FillFormatType.Solid; textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink); textRange.EastAsianFont = new TextFont(font.Name); textRange.FontHeight = font.Size; x += (100 + size.Width); } x = 30; y += (100 + size.Height); } //保存文档 presentation.SaveToFile("Watermark_result.pptx", FileFormat.Pptx2010); } } }

VB.NET

Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace WatermarkDemo
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            '加载示例文档
            Dim presentation As Presentation = New Presentation
            presentation.LoadFromFile("Sample.pptx")
            '获取文本大小
            Dim font As Font = New Font("宋体", 20)
            Dim watermarkText As String = "冰蓝科技"
            Dim size As SizeF = TextRenderer.MeasureText("E-iceblue", font)
            Dim x As Single = 30
            Dim y As Single = 80
            Dim i As Integer = 0
            Do While (i < 3) Dim j As Integer = 0 Do While (j < 3) '绘制文本,设置文本格式并将其添加到第一张幻灯片 Dim rect As RectangleF = New RectangleF(x, y, size.Width, size.Height) Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect) shape.Fill.FillType = FillFormatType.None shape.ShapeStyle.LineColor.Color = Color.White shape.Rotation = -45 shape.Locking.SelectionProtection = true shape.Line.FillType = FillFormatType.None shape.TextFrame.Text = watermarkText Dim textRange As TextRange = shape.TextFrame.TextRange textRange.Fill.FillType = FillFormatType.Solid textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink) textRange.EastAsianFont = New TextFont(font.Name) textRange.FontHeight = font.Size x = (x + (100 + size.Width)) j = (j + 1) Loop x = 30 y = (y + (100 + size.Height)) i = (i + 1) Loop '保存文档 presentation.SaveToFile("Watermark_result.pptx", FileFormat.Pptx2010) End Sub End Class End Namespace

效果图:

国产PPT格式控件Spire.Presentation功能演示:替换 PPT 中的视频、音频文件


还想要更多吗?您可以点击阅读【2020 · E-iceblue最新资源整合】查找需要的教程资源。慧都是E-iceblue官方友好合作伙伴,如果您对spire.Presentation感兴趣,可以了解具体授权价格和使用机制。

标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP