翻譯|使用教程|編輯:李顯亮|2021-02-24 10:59:57.787|閱讀 337 次
概述:本文將詳細(xì)介紹如何使用C# 、VB.NET給PowerPoint文檔添加多行多列文本水印。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
Spire.Presentation for .NET 是專(zhuān)業(yè)的 PowerPoint組件,開(kāi)發(fā)者可以在 .NET 平臺(tái)上對(duì) PPT文檔進(jìn)行生成、修改、轉(zhuǎn)換和打印等操作,而無(wú)需安裝 Microsoft PowerPoint。
本文將詳細(xì)介紹如何使用C# 、VB.NET給PowerPoint文檔添加多行多列文本水印。可點(diǎn)擊此處下載最新版測(cè)試。
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 = "冰藍(lán)科技"; 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++) { //繪制文本,設(shè)置文本格式并將其添加到第一張幻燈片 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 = "冰藍(lán)科技" 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) '繪制文本,設(shè)置文本格式并將其添加到第一張幻燈片 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
效果圖:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn