冰蓝科技
|
028-81705109
|
|
微信扫一扫
|

Spire.Cloud 纯前端文档控件

在开发团队的共同努力之下,冰蓝科技于今日推出了Spire.XLS for Android via Java 2.2.0。该产品是一款专业的 Android Excel 控件,用于在 Android 手机应用程序中创建、读取、操作和转换 Excel 文档。以下是该产品的主要功能:


获取Spire.XLS for Android via Java 2.2.0更详细的信息,请点击:

https://www.e-iceblue.cn/Introduce/xls-for-android-via-java.html

本文将详细介绍如何使用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

效果图:

添加多行多列文本水印至 PowerPoint 幻灯片文档

本文介绍如何使用Spire.Presentation for Java为PPT文档中的文字设置阴影效果。

import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;
import com.spire.presentation.drawing.OuterShadowEffect;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class SetShadowEffect {

    public static void main(String[] args) throws Exception {

        //创建Presentation对象
        Presentation presentation = new Presentation();
        presentation.getSlideSize().setType(SlideSizeType.SCREEN_16_X_9);

        //获取第一个幻灯片
        ISlide slide = presentation.getSlides().get(0);

        //添加一个矩形
        IAutoShape shape = slide.getShapes().appendShape(ShapeType.RECTANGLE,new Rectangle2D.Float(50,80,350,100));
        shape.getFill().setFillType(FillFormatType.NONE);
        shape.getLine().setFillType(FillFormatType.NONE);

        //设置矩形文字
        shape.appendTextFrame("文字阴影效果");

        //设置文字样式
        shape.getTextFrame().getTextRange().setFontHeight(38f);
        shape.getTextFrame().getTextRange().setLatinFont(new TextFont("黑体"));
        shape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        shape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK);

        //创建OuterShadowEffect对象
        OuterShadowEffect outerShadow= new OuterShadowEffect();

        //设置阴影样式
        outerShadow.setBlurRadius(0);
        outerShadow.setDirection(50);
        outerShadow.setDistance(10);
        outerShadow.getColorFormat().setColor(Color.orange);

        //应用阴影到文字
        shape.getTextFrame().getTextRange().getEffectDag().setOuterShadowEffect(outerShadow);

        //保存文档
        presentation.saveToFile("output/AddShadow-cn.pptx", FileFormat.PPTX_2013);
    }
}

Java 为 PPT 中的文字添加阴影效果

Spire.XLS 11.2.6已发布。该版本支持修改透视表的数据源,增强了转换Excel到PDF的功能,同时还修复了加载XLSM文件时出现的问题。详情请阅读以下内容。

新功能:

问题修复:


下载Spire.XLS 11.2.6请点击:

https://www.e-iceblue.cn/Downloads/Spire-XLS-NET.html

Spire.Doc for .NET支持给Word文档设置背景,可设置单一颜色、渐变颜色以及图片背景。设置背景时,常见的方法是为整篇文章设置统一的背景,即每个页面的背景都是一样的,如这篇文章中的方法。本文,将介绍如何来给Word中的不同页面设置不同背景。具体分以下情况来设置。

1、只需设置首页背景和其他页面不同

1.1 设置纯色背景

C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace DifferentBackground1
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载Word测试文档
            Document doc = new Document();
            doc.LoadFromFile("测试.docx");

            //获取第一节
            Section section = doc.Sections[0];

            //设置首页页眉页脚不同
            section.PageSetup.DifferentFirstPageHeaderFooter = true;

            //在首页页眉添加形状
            HeaderFooter firstpageheader = section.HeadersFooters.FirstPageFooter;//获取首页页眉
            firstpageheader.Paragraphs.Clear();//清除页眉默认的段落格式(因默认页眉格式中包含有一条横线)
            Paragraph firstpara = firstpageheader.AddParagraph();//重新添加段落
            float width = section.PageSetup.PageSize.Width;//获取页面宽度、高度
            float height = section.PageSetup.PageSize.Height;
            ShapeObject shape = firstpara.AppendShape(width, height, ShapeType.Rectangle);//添加形状
            shape.BehindText = true;//设置形状衬于文字下方
            shape.HorizontalAlignment = ShapeHorizontalAlignment.Center;//设置对齐方式,铺满页面
            shape.VerticalOrigin = VerticalOrigin.TopMarginArea;
            shape.FillColor = Color.LightBlue;//形状颜色


            //在其他页面的页眉中添加形状
            HeaderFooter otherheader = section.HeadersFooters.Header;
            otherheader.Paragraphs.Clear();
            Paragraph otherpara = otherheader.AddParagraph();
            ShapeObject shape1 = otherpara.AppendShape(width, height, ShapeType.Rectangle);
            shape1.BehindText = true;
            shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            shape1.VerticalOrigin = VerticalOrigin.TopMarginArea;
            shape1.FillColor = Color.Pink;

            //保存文档
            doc.SaveToFile("ColorBackground1.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("ColorBackground1.docx");
        }
    }
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing

Namespace DifferentBackground1
	Class Program
		Private Shared Sub Main(args As String())
			'加载Word测试文档
			Dim doc As New Document()
			doc.LoadFromFile("测试.docx")

			'获取第一节
			Dim section As Section = doc.Sections(0)

			'设置首页页眉页脚不同
			section.PageSetup.DifferentFirstPageHeaderFooter = True

			'在首页页眉添加形状
			Dim firstpageheader As HeaderFooter = section.HeadersFooters.FirstPageFooter
			'获取首页页眉
			firstpageheader.Paragraphs.Clear()
			'清除页眉默认的段落格式(因默认页眉格式中包含有一条横线)
			Dim firstpara As Paragraph = firstpageheader.AddParagraph()
			'重新添加段落
			Dim width As Single = section.PageSetup.PageSize.Width
			'获取页面宽度、高度
			Dim height As Single = section.PageSetup.PageSize.Height
			Dim shape As ShapeObject = firstpara.AppendShape(width, height, ShapeType.Rectangle)
			'添加形状
			shape.BehindText = True
			'设置形状衬于文字下方
			shape.HorizontalAlignment = ShapeHorizontalAlignment.Center
			'设置对齐方式,铺满页面
			shape.VerticalOrigin = VerticalOrigin.TopMarginArea
			shape.FillColor = Color.LightBlue
			'形状颜色

			'在其他页面的页眉中添加形状
			Dim otherheader As HeaderFooter = section.HeadersFooters.Header
			otherheader.Paragraphs.Clear()
			Dim otherpara As Paragraph = otherheader.AddParagraph()
			Dim shape1 As ShapeObject = otherpara.AppendShape(width, height, ShapeType.Rectangle)
			shape1.BehindText = True
			shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center
			shape1.VerticalOrigin = VerticalOrigin.TopMarginArea
			shape1.FillColor = Color.Pink

			'保存文档
			doc.SaveToFile("ColorBackground1.docx", FileFormat.Docx2013)
			System.Diagnostics.Process.Start("ColorBackground1.docx")
		End Sub
	End Class
End Namespace

C#/VB.NET 给 Word 不同页面设置不同背景

1.2 设置图片背景

C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace DifferentBackground1
{
    class Program
    {
        static void Main(string[] args)
        {
             //加载Word测试文档
            Document doc = new Document();
            doc.LoadFromFile("测试.docx");

            //获取第一节
            Section section = doc.Sections[0];

            //设置首页页眉页脚不同
            section.PageSetup.DifferentFirstPageHeaderFooter = true;

            HeaderFooter firstpageheader = section.HeadersFooters.FirstPageFooter;//获取首页页眉
            firstpageheader.Paragraphs.Clear();//清除页眉默认的段落格式(因默认页眉格式中包含有一条横线)
            Paragraph firstpara = firstpageheader.AddParagraph();//重新添加段落

            //获取页面宽度、高度
            float width = section.PageSetup.PageSize.Width;
            float height = section.PageSetup.PageSize.Height; 
          
            //添加图片到首页页眉
            DocPicture pic0 = firstpara.AppendPicture("1.png");
            pic0.TextWrappingStyle = TextWrappingStyle.Behind;
            pic0.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            pic0.VerticalOrigin = VerticalOrigin.TopMarginArea;
            pic0.Width = width;
            pic0.Height = height;


            //在其他页面的页眉中添加图片
            HeaderFooter otherheader = section.HeadersFooters.Header;
            otherheader.Paragraphs.Clear();
            Paragraph otherpara = otherheader.AddParagraph();
            DocPicture pic1 = otherpara.AppendPicture("2.png");
            pic1.TextWrappingStyle = TextWrappingStyle.Behind;
            pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            pic1.VerticalOrigin = VerticalOrigin.TopMarginArea;
            pic1.Width = width;
            pic1.Height = height;

            //保存文档
            doc.SaveToFile("ImageBackground1.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("ImageBackground1.docx");
        }
    }
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace DifferentBackground1
	Class Program
		Private Shared Sub Main(args As String())
			'加载Word测试文档
			Dim doc As New Document()
			doc.LoadFromFile("测试.docx")

			'获取第一节
			Dim section As Section = doc.Sections(0)

			'设置首页页眉页脚不同
			section.PageSetup.DifferentFirstPageHeaderFooter = True

			Dim firstpageheader As HeaderFooter = section.HeadersFooters.FirstPageFooter
			'获取首页页眉
			firstpageheader.Paragraphs.Clear()
			'清除页眉默认的段落格式(因默认页眉格式中包含有一条横线)
			Dim firstpara As Paragraph = firstpageheader.AddParagraph()
			'重新添加段落
			'获取页面宽度、高度
			Dim width As Single = section.PageSetup.PageSize.Width
			Dim height As Single = section.PageSetup.PageSize.Height

			'添加图片到首页页眉
			Dim pic0 As DocPicture = firstpara.AppendPicture("1.png")
			pic0.TextWrappingStyle = TextWrappingStyle.Behind
			pic0.HorizontalAlignment = ShapeHorizontalAlignment.Center
			pic0.VerticalOrigin = VerticalOrigin.TopMarginArea
			pic0.Width = width
			pic0.Height = height

			'在其他页面的页眉中添加图片
			Dim otherheader As HeaderFooter = section.HeadersFooters.Header
			otherheader.Paragraphs.Clear()
			Dim otherpara As Paragraph = otherheader.AddParagraph()
			Dim pic1 As DocPicture = otherpara.AppendPicture("2.png")
			pic1.TextWrappingStyle = TextWrappingStyle.Behind
			pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center
			pic1.VerticalOrigin = VerticalOrigin.TopMarginArea
			pic1.Width = width
			pic1.Height = height

			'保存文档
			doc.SaveToFile("ImageBackground1.docx", FileFormat.Docx2013)
			System.Diagnostics.Process.Start("ImageBackground1.docx")
		End Sub
	End Class
End Namespace

C#/VB.NET 给 Word 不同页面设置不同背景

2、设置指定多个页面背景不同

注意:给多个页面设置不同背景时,需要通过获取不同节的页眉来设置,本次程序环境中所用源文档已设置了多个节,如需手动设置分节,请参考这篇文章

2.1 设置纯色背景

C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace DifferentBackground2
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载Word文档
            Document doc = new Document();
            doc.LoadFromFile("测试.docx");

            //获取第一节
            Section section1 = doc.Sections[0];

            //获取页面宽度、高度
            float width = section1.PageSetup.PageSize.Width;
            float height = section1.PageSetup.PageSize.Height;

            //添加图片到页眉
            HeaderFooter header1 = section1.HeadersFooters.Header;
            header1.Paragraphs.Clear();
            Paragraph para1 = header1.AddParagraph();
            ShapeObject shape1 = para1.AppendShape(width, height, ShapeType.Rectangle);//添加形状
            shape1.BehindText = true;//设置形状衬于文字下方
            shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center;//设置对齐方式,铺满页面
            shape1.VerticalOrigin = VerticalOrigin.TopMarginArea;
            shape1.FillColor = Color.LightSalmon;//形状颜色

            //同理设置第二节页眉中的图片
            Section section2 = doc.Sections[1];
            HeaderFooter header2 = section2.HeadersFooters.Header;
            header2.Paragraphs.Clear();
            Paragraph para2 = header2.AddParagraph();
            ShapeObject shape2 = para2.AppendShape(width, height, ShapeType.Rectangle);//添加形状
            shape2.BehindText = true;//设置形状衬于文字下方
            shape2.HorizontalAlignment = ShapeHorizontalAlignment.Center;//设置对齐方式,铺满页面
            shape2.VerticalOrigin = VerticalOrigin.TopMarginArea;
            shape2.FillColor = Color.Moccasin;//形状颜色

            //同理设置第三节中的页眉中的图片
            Section section3 = doc.Sections[2];
            HeaderFooter header3 = section3.HeadersFooters.Header;
            header3.Paragraphs.Clear();
            Paragraph para3 = header3.AddParagraph();
            ShapeObject shape3 = para3.AppendShape(width, height, ShapeType.Rectangle);//添加形状
            shape3.BehindText = true;//设置形状衬于文字下方
            shape3.HorizontalAlignment = ShapeHorizontalAlignment.Center;//设置对齐方式,铺满页面
            shape3.VerticalOrigin = VerticalOrigin.TopMarginArea;
            shape3.FillColor = Color.LawnGreen;//形状颜色

            //保存文档
            doc.SaveToFile("ColorBackground2.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("ColorBackground2.docx");
        }
    }
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports System.Drawing

Namespace DifferentBackground2
	Class Program
		Private Shared Sub Main(args As String())
			'加载Word文档
			Dim doc As New Document()
			doc.LoadFromFile("测试.docx")

			'获取第一节
			Dim section1 As Section = doc.Sections(0)

			'获取页面宽度、高度
			Dim width As Single = section1.PageSetup.PageSize.Width
			Dim height As Single = section1.PageSetup.PageSize.Height

			'添加图片到页眉
			Dim header1 As HeaderFooter = section1.HeadersFooters.Header
			header1.Paragraphs.Clear()
			Dim para1 As Paragraph = header1.AddParagraph()
			Dim shape1 As ShapeObject = para1.AppendShape(width, height, ShapeType.Rectangle)
			'添加形状
			shape1.BehindText = True
			'设置形状衬于文字下方
			shape1.HorizontalAlignment = ShapeHorizontalAlignment.Center
			'设置对齐方式,铺满页面
			shape1.VerticalOrigin = VerticalOrigin.TopMarginArea
			shape1.FillColor = Color.LightSalmon
			'形状颜色
			'同理设置第二节页眉中的图片
			Dim section2 As Section = doc.Sections(1)
			Dim header2 As HeaderFooter = section2.HeadersFooters.Header
			header2.Paragraphs.Clear()
			Dim para2 As Paragraph = header2.AddParagraph()
			Dim shape2 As ShapeObject = para2.AppendShape(width, height, ShapeType.Rectangle)
			'添加形状
			shape2.BehindText = True
			'设置形状衬于文字下方
			shape2.HorizontalAlignment = ShapeHorizontalAlignment.Center
			'设置对齐方式,铺满页面
			shape2.VerticalOrigin = VerticalOrigin.TopMarginArea
			shape2.FillColor = Color.Moccasin
			'形状颜色
			'同理设置第三节中的页眉中的图片
			Dim section3 As Section = doc.Sections(2)
			Dim header3 As HeaderFooter = section3.HeadersFooters.Header
			header3.Paragraphs.Clear()
			Dim para3 As Paragraph = header3.AddParagraph()
			Dim shape3 As ShapeObject = para3.AppendShape(width, height, ShapeType.Rectangle)
			'添加形状
			shape3.BehindText = True
			'设置形状衬于文字下方
			shape3.HorizontalAlignment = ShapeHorizontalAlignment.Center
			'设置对齐方式,铺满页面
			shape3.VerticalOrigin = VerticalOrigin.TopMarginArea
			shape3.FillColor = Color.LawnGreen
			'形状颜色
			'保存文档
			doc.SaveToFile("ColorBackground2.docx", FileFormat.Docx2013)
			System.Diagnostics.Process.Start("ColorBackground2.docx")
		End Sub
	End Class
End Namespace

C#/VB.NET 给 Word 不同页面设置不同背景

2.2 设置图片背景

C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace DifferentBackground2
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载Word文档
            Document doc = new Document();
            doc.LoadFromFile("测试.docx");

            //获取第一节
            Section section1 = doc.Sections[0];
            //添加图片到页眉
            HeaderFooter header1 = section1.HeadersFooters.Header;
            header1.Paragraphs.Clear();
            Paragraph para1 = header1.AddParagraph();
            DocPicture pic1 = para1.AppendPicture("1.png");
            pic1.TextWrappingStyle = TextWrappingStyle.Behind;
            pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            pic1.VerticalOrigin = VerticalOrigin.TopMarginArea;
            float width = section1.PageSetup.PageSize.Width;
            float height = section1.PageSetup.PageSize.Height;
            pic1.Width = width;
            pic1.Height = height;

            //同理设置第二节页眉中的图片
            Section section2 = doc.Sections[1];
            HeaderFooter header2 = section2.HeadersFooters.Header;
            header2.Paragraphs.Clear();
            Paragraph para2 = header2.AddParagraph();
            DocPicture pic2 = para2.AppendPicture("2.png");
            pic2.TextWrappingStyle = TextWrappingStyle.Behind;
            pic2.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            pic2.VerticalOrigin = VerticalOrigin.TopMarginArea; 
            pic2.Width = width;
            pic2.Height = height;

            //同理设置第三节中的页眉中的图片
            Section section3 = doc.Sections[2];
            HeaderFooter header3 = section3.HeadersFooters.Header;
            header3.Paragraphs.Clear();
            Paragraph para3 = header3.AddParagraph();
            DocPicture pic3 = para3.AppendPicture("3.png");
            pic3.TextWrappingStyle = TextWrappingStyle.Behind;
            pic3.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            pic3.VerticalOrigin = VerticalOrigin.TopMarginArea;
            pic3.Width = width;
            pic3.Height = height;

            //保存文档
            doc.SaveToFile("ImageBackground2.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("ImageBackground2.docx");
        }
    }
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields

Namespace DifferentBackground2
	Class Program
		Private Shared Sub Main(args As String())
			'加载Word文档
			Dim doc As New Document()
			doc.LoadFromFile("测试.docx")

			'获取第一节
			Dim section1 As Section = doc.Sections(0)
			'添加图片到页眉
			Dim header1 As HeaderFooter = section1.HeadersFooters.Header
			header1.Paragraphs.Clear()
			Dim para1 As Paragraph = header1.AddParagraph()
			Dim pic1 As DocPicture = para1.AppendPicture("1.png")
			pic1.TextWrappingStyle = TextWrappingStyle.Behind
			pic1.HorizontalAlignment = ShapeHorizontalAlignment.Center
			pic1.VerticalOrigin = VerticalOrigin.TopMarginArea
			Dim width As Single = section1.PageSetup.PageSize.Width
			Dim height As Single = section1.PageSetup.PageSize.Height
			pic1.Width = width
			pic1.Height = height

			'同理设置第二节页眉中的图片
			Dim section2 As Section = doc.Sections(1)
			Dim header2 As HeaderFooter = section2.HeadersFooters.Header
			header2.Paragraphs.Clear()
			Dim para2 As Paragraph = header2.AddParagraph()
			Dim pic2 As DocPicture = para2.AppendPicture("2.png")
			pic2.TextWrappingStyle = TextWrappingStyle.Behind
			pic2.HorizontalAlignment = ShapeHorizontalAlignment.Center
			pic2.VerticalOrigin = VerticalOrigin.TopMarginArea
			pic2.Width = width
			pic2.Height = height

			'同理设置第三节中的页眉中的图片
			Dim section3 As Section = doc.Sections(2)
			Dim header3 As HeaderFooter = section3.HeadersFooters.Header
			header3.Paragraphs.Clear()
			Dim para3 As Paragraph = header3.AddParagraph()
			Dim pic3 As DocPicture = para3.AppendPicture("3.png")
			pic3.TextWrappingStyle = TextWrappingStyle.Behind
			pic3.HorizontalAlignment = ShapeHorizontalAlignment.Center
			pic3.VerticalOrigin = VerticalOrigin.TopMarginArea
			pic3.Width = width
			pic3.Height = height

			'保存文档
			doc.SaveToFile("ImageBackground2.docx", FileFormat.Docx2013)
			System.Diagnostics.Process.Start("ImageBackground2.docx")
		End Sub
	End Class
End Namespace

C#/VB.NET 给 Word 不同页面设置不同背景

Spire PDF 7.2.9已发布。该版本支持添加page-piece字典,增强了转换PDF到XPS/图片/Excel的功能。此外,该版本还修复了保存和打印PDF文档时出现的问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.PDF 7.2.9请点击:

https://www.e-iceblue.cn/Downloads/Spire-PDF-NET.html

本文介绍使用Spire.Presentation for .NET来替换PPT已插入的视频、音频文件,在替换原有视频、音频文件时,可设置替换原有视频封面、音频形状颜色等。

C#
using Spire.Presentation;
using Spire.Presentation.Collections;
using Spire.Presentation.Drawing;
using System.Drawing;
using System.IO;

namespace ReplaceVideo
{
    class Program
    {
        static void Main(string[] args)
        {
            //加载PPT文档
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("test.pptx");

            //获取视频、音频文件集合
            VideoCollection videos = ppt.Videos;
            WavAudioCollection audios = ppt.WavAudios;

            //遍历所有幻灯片
            foreach (ISlide slide in ppt.Slides)
            {
                //遍历幻灯片中的所有形状
                foreach (Shape shape in slide.Shapes)
                {
                    //替换视频文件
                    if (shape is IVideo)
                    {
                        IVideo video = shape as IVideo;
                        byte[] bts = File.ReadAllBytes("newVideo.mp4");
                        VideoData videoData = videos.Append(bts);
                        video.EmbeddedVideoData = videoData;  
                        Image image = Image.FromFile("jds.png");//加载图片
                        IImageData coverImage = ppt.Images.Append(image);
                        video.EmbedImage = coverImage;//设置视频封面图片
                    }

                    //替换音频文件
                    if(shape is IAudio)
                    {
                        IAudio audio = shape as IAudio;
                        byte[] bts1 = File.ReadAllBytes("newAudio.mp3");
                        IAudioData audiodata = audios.Append(bts1);
                        audio.Data = audiodata;
                        audio.Fill.SolidColor.Color = Color.GreenYellow;
                    }
                }
            }

            //保存文档
            ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
            System.Diagnostics.Process.Start("result.pptx");
        }
    }
}
VB.NET
Imports Spire.Presentation
Imports Spire.Presentation.Collections
Imports Spire.Presentation.Drawing
Imports System.Drawing
Imports System.IO

Namespace ReplaceVideo
	Class Program
		Private Shared Sub Main(args As String())
			'加载PPT文档
			Dim ppt As New Presentation()
			ppt.LoadFromFile("test.pptx")

			'获取视频、音频文件集合
			Dim videos As VideoCollection = ppt.Videos
			Dim audios As WavAudioCollection = ppt.WavAudios

			'遍历所有幻灯片
			For Each slide As ISlide In ppt.Slides
				'遍历幻灯片中的所有形状
				For Each shape As Shape In slide.Shapes
					'替换视频文件
					If TypeOf shape Is IVideo Then
						Dim video As IVideo = TryCast(shape, IVideo)
						Dim bts As Byte() = File.ReadAllBytes("newVideo.mp4")
						Dim videoData As VideoData = videos.Append(bts)
						video.EmbeddedVideoData = videoData
						Dim image__1 As Image = Image.FromFile("jds.png")
						'加载图片
						Dim coverImage As IImageData = ppt.Images.Append(image__1)
							'设置视频封面图片
						video.EmbedImage = coverImage
					End If

					'替换音频文件
					If TypeOf shape Is IAudio Then
						Dim audio As IAudio = TryCast(shape, IAudio)
						Dim bts1 As Byte() = File.ReadAllBytes("newAudio.mp3")
						Dim audiodata As IAudioData = audios.Append(bts1)
						audio.Data = audiodata
						audio.Fill.SolidColor.Color = Color.GreenYellow
					End If
				Next
			Next

			'保存文档
			ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
			System.Diagnostics.Process.Start("result.pptx")
		End Sub
	End Class
End Namespace

替换效果:

C#/VB.NET 替换 PPT 中的视频、音频文件

尊敬的新老客户:

2021年春节将至,成都冰蓝科技有限公司全体职工在此感谢您在过去一年里的鼎力支持与厚爱,向您与您的家人致以最诚挚的祝福和问候!为落实节日期间的合作事宜,我司就春节放假做出如下通知:

因放假给您造成的不便之处,敬请谅解。

恭祝:新春快乐,牛年大吉!


邮件联系方式

Spire.Office 6.2.1已发布。本次更新带了一些新的功能,譬如:Spire.PDF 支持检测 PDF 是否是加密文档,支持转换PDF为灰度文档,以及新增了替换文本方法;Spire.Presentation支持了替换视频文件的功能。此外,该版本还修复了大量的问题。详情请阅读以下内容。

该版本涵盖了最新版的Spire.Doc, Spire.PDF, Spire.XLS, Spire.Presentation, Spire.Email, Spire.DocViewer, Spire.PDFViewer, Spire.Spreadsheet, Spire.OfficeViewer, Spire.DataExport, Spire.Barcode。

版本信息如下:

获取Spire.Office 6.2.1请点击:

https://www.e-iceblue.cn/Downloads/Spire-Office-NET.html


Spire.PDF

新功能:

问题修复:


Spire.Presentation

新功能:

问题修复:


Spire.Doc

问题修复:


Spire.XLS

问题修复:

Spire.XLS 11.2.3已发布。该版本增强了转换XLSM/Excel到PDF的功能,并且修复了加载XLSX文档时出现的问题。详情请阅读以下内容。

问题修复:


下载Spire.XLS 11.2.3请点击:

https://www.e-iceblue.cn/Downloads/Spire-XLS-NET.html