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

Spire.Cloud 纯前端文档控件

本文介绍如何使用Spire.PDF for Java在PDF文档中添加多级列表。

import com.spire.pdf.PdfDocument;
import com.spire.pdf.PdfNumberStyle;
import com.spire.pdf.PdfPageBase;
import com.spire.pdf.PdfPageSize;
import com.spire.pdf.graphics.*;
import com.spire.pdf.lists.PdfListItem;
import com.spire.pdf.lists.PdfOrderedMarker;
import com.spire.pdf.lists.PdfSortedList;

import java.awt.*;
import java.awt.geom.Point2D;

public class CreateMultiLevelList {

    public static void main(String[] args) {

        //创建PdfDocument对象
        PdfDocument doc = new PdfDocument();

        //设置页边距
        PdfMargins margin = new PdfMargins(60, 60, 40, 40);

        //添加一页
        PdfPageBase page = doc.getPages().add(PdfPageSize.A4, margin);

        //初始化x,y坐标
        float x = 0;
        float y = 15;

        //创建两个画刷
        PdfBrush blackBrush = PdfBrushes.getBlack();
        PdfBrush purpleBrush = PdfBrushes.getPurple();

        //创建两个字体
        PdfTrueTypeFont titleFont = new PdfTrueTypeFont(new Font("微软雅黑",Font.BOLD,9),true);
        PdfTrueTypeFont listFont = new PdfTrueTypeFont(new Font("微软雅黑",Font.PLAIN,9),true);

        //在指定位置绘制标题
        String title = "XHTML常见问题 :";
        page.getCanvas().drawString(title, titleFont, blackBrush, x, y);
        y = y + (float) titleFont.measureString(title).getHeight();
        y = y + 5;

        //创建两个ordered makers,用于设置有序列表的符号
        PdfOrderedMarker marker1 = new PdfOrderedMarker(PdfNumberStyle.Upper_Roman, listFont);
        PdfOrderedMarker marker2 = new PdfOrderedMarker(PdfNumberStyle.Numeric, listFont);

        //创建一个父列表
        String parentListContent = "XHTML 1.0简介\n"
                + "标签和属性语法介绍";
        PdfSortedList parentList = new PdfSortedList(parentListContent);
        parentList.setFont(listFont);
        parentList.setIndent(8);
        parentList.setBrush(purpleBrush);
        parentList.setMarker(marker1);

        //创建一个列表 - "subList_1"
        String subListContent_1 = "什么是XHTML?\n"
                + "XHMTL文档是什么样的?\n"
                + "XHTML和HTML之间有什么关系?\n"
                + "XHTML和XML之间有什么关系?";
        PdfSortedList subList_1 = new PdfSortedList(subListContent_1);
        subList_1.setIndent(16);
        subList_1.setFont(listFont);
        subList_1.setBrush(purpleBrush);
        subList_1.setMarker(marker2);

        //创建另一个列表 -"subList_2"
        String subListContent_2 = "什么是XHTML的元素?\n"
                + "如何在XHTML文档中添加注释?\n"
                + "如何为XHTML元素写一个开始标签?";
        PdfSortedList subList_2 = new PdfSortedList(subListContent_2);
        subList_2.setIndent(16);
        subList_2.setFont(listFont);
        subList_2.setBrush(purpleBrush);
        subList_2.setMarker(marker2);

        //将subList_1设置为父列表第一个元素下的子列表
        PdfListItem item_1 = parentList.getItems().get(0);
        item_1.setSubList(subList_1);

        //将subList_2设置为父列表第二个元素下的子列表
        PdfListItem item_2 = parentList.getItems().get(1);
        item_2.setSubList(subList_2);

        //绘制父列表到指定位置
        PdfTextLayout textLayout = new PdfTextLayout();
        textLayout.setBreak(PdfLayoutBreakType.Fit_Page);
        textLayout.setLayout(PdfLayoutType.Paginate);
        parentList.draw(page,new Point2D.Float(x,y),textLayout);

        //保存文档
        doc.saveToFile("MultiLevelList.pdf");
    }
}

Java 在 PDF 中创建多级列表

本文将介绍如何使用Spire.Doc for Java验证Word文档的限制编辑密码是否正确。

import com.spire.doc.Document;

public class VerifyRestrictEditingPassword {
    public static void main(String[] args) {
        //创建Document实例
        Document document = new Document();
        //加载Word文档
        document.loadFromFile("Input.docx");

        //验证文档的限制编辑密码是否正确
        boolean result = document.checkProtectionPassWord("123");

        if(!result) {
            System.out.println("密码错误!");
        }
        else {
            System.out.println("密码正确!");
        }
    }
}

结果:

Java 验证 Word 文档的限制编辑密码

该文将详细介绍如何使用Spire.Doc for Java添加Latex 数学公式和 MathMLCode到word 文档。

import com.spire.doc.*;
import com.spire.doc.documents.*;
import com.spire.doc.fields.omath.*;

public class Test {
    public static void main(String[] args){
        //新建Word示例,添加一个section
        Document doc = new Document();
        Section section = doc.addSection();
        //添加段落
        Paragraph paragraph = section.addParagraph();

        //插入Latex 数学公式
        OfficeMath officeMath = new OfficeMath(doc);
        paragraph.getItems().add(officeMath);
        officeMath.fromLatexMathCode("x^{2}+\\sqrt{{x^{2}+1}}+1");

        //添加段落二
        Paragraph paragraph2 = section.addParagraph();

        //插入MathMLCode数学公式
        OfficeMath officeMath2 = new OfficeMath(doc);
        paragraph2.getItems().add(officeMath2);
        officeMath2.fromMathMLCode("<mml:math xmlns:mml=\"http://www.w3.org/1998/Math/MathML\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\"><mml:msup><mml:mrow><mml:mi>x</mml:mi></mml:mrow><mml:mrow><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mo>+</mml:mo><mml:msqrt><mml:msup><mml:mrow><mml:mi>x</mml:mi></mml:mrow><mml:mrow><mml:mn>2</mml:mn></mml:mrow></mml:msup><mml:mo>+</mml:mo><mml:mn>1</mml:mn></mml:msqrt><mml:mo>+</mml:mo><mml:mn>1</mml:mn></mml:math>");

        //保存文档
        String result = "output/addMathEquation.docx";
        doc.saveToFile(result, FileFormat.Docx_2013);
    }
}

效果图:

Java 添加 Word 数学公式

数字签名是一种应用于数字数据的电子加密身份验证戳记,主要用于确认来自签名者的信息以及文档内容未被篡改。本文,将介绍如何使用 Spire.Doc for Java 以编程方式向 Word 文档添加数字签名。

安装 Spire.Doc for Java

首先,您需要在 Java 程序中添加 Spire.Doc.jar 文件作为依赖项。JAR 文件可以从此链接下载。 如果您使用 Maven,则可以将以下代码添加到项目的 pom.xml 文件中,从而在应用程序中导入 JAR 文件。

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.cn/repository/maven-public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.doc</artifactId>
        <version>14.9.5</version>
    </dependency>
</dependencies>

添加数字签名

向 Word 文档添加数字签名时,可参考如下主要代码步骤:

  • Java
import com.spire.doc.*;

public class AddSignature {
    public static void main(String[] args) {
        //加载Word文档
        Document doc = new Document();
        doc.loadFromFile("sample.docx");
        
        //添加数字签名,并保存文档
        doc.saveToFile("AddSignature.docx",FileFormat.Docx_2013,"Cermia.pfx","123654yes!");
    }
}

签名添加效果:

Java 给 Word 添加数字签名

申请临时 License

如果您希望删除结果文档中的评估消息,或者摆脱功能限制,请 该Email地址已收到反垃圾邮件插件保护。要显示它您需要在浏览器中启用JavaScript。 获取有效期 30 天的临时许可证。

Spire.Doc for Java 4.5.1已发布。该版本支持验证文档的保护密码,增强了Word到PDF/HTML/SVG的转换功能,同时还修复了加载和合并文档等时出现的问题。详情请阅读以下内容。

新功能:

问题修复:


获取Spire.Doc for Java 4.5.1请点击:

https://www.e-iceblue.cn/Downloads/Spire-Doc-JAVA.html

本文介绍如何使用Spire.Doc在Word文档中添加超链接链接到文档内的某个书签。

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

namespace WordCodeExamples
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建Document对象
            Document doc = new Document();

            //添加两个节
            Section section1 = doc.AddSection();
            Section section2 = doc.AddSection();

            //在第二节中添加一个段落,并在段落上添加书签“myBookmark”
            Paragraph bookmarkParagrapg = section2.AddParagraph();
            bookmarkParagrapg.AppendText("这里有一个书签myBookmark");
            BookmarkStart start = bookmarkParagrapg.AppendBookmarkStart("myBookmark");
            bookmarkParagrapg.Items.Insert(0, start);
            bookmarkParagrapg.AppendBookmarkEnd("myBookmark");

            //在第一节中添加段落,并添加一个链接到书签的超链接
            Paragraph paragraph = section1.AddParagraph();
            paragraph.AppendText("链接到书签: ");
            paragraph.AppendHyperlink("myBookmark", "跳转至指定书签", HyperlinkType.Bookmark);

            //保存文档
            doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013);
        }
    }
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace WordCodeExamples
    Class Program
        Shared  Sub Main(ByVal args() As String)
            '创建Document对象
            Document doc = New Document()
 
            '添加两个节
            Dim section1 As Section = doc.AddSection()
            Dim section2 As Section = doc.AddSection()
 
            '在第二节中添加一个段落,并在段落上添加书签“myBookmark”
            Dim bookmarkParagrapg As Paragraph = section2.AddParagraph()
            bookmarkParagrapg.AppendText("这里有一个书签myBookmark")
            Dim start As BookmarkStart = bookmarkParagrapg.AppendBookmarkStart("myBookmark")
            bookmarkParagrapg.Items.Insert(0, start)
            bookmarkParagrapg.AppendBookmarkEnd("myBookmark")
 
            '在第一节中添加段落,并添加一个链接到书签的超链接
            Dim paragraph As Paragraph = section1.AddParagraph()
            paragraph.AppendText("链接到书签: ")
            paragraph.AppendHyperlink("myBookmark", "跳转至指定书签", HyperlinkType.Bookmark)
 
            '保存文档
            doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013)
        End Sub
    End Class
End Namespace

C#/VB.NET Word 中添加超链接链接到书签

Java 自动化提取 Excel 文件中的批注图片

在处理各类 Excel 数据报表时,批注常被用来补充说明、给出修改建议或标注关键信息。为了让这些提示更加直观清晰,我们有时会在批注中设置背景图片。然而,当需要再次使用这些图片或将其保存到本地时,手动提取往往步骤繁琐、效率低下。本文将详细讲解如何使用 Java 提取 Excel 批注中的图片,既包括获取指定批注的背景图,也涵盖批量提取所有批注背景图的实现方式,帮助你省去重复的手动操作,提升处理 Excel 文件的效率。

一、 环境准备

在进入今天的正题之前,我们需要确保开发环境已经就绪。

  1. 核心库选型:我们选用 Spire.XLS for Java,这是是一款功能强大的独立 Excel 组件,无需在服务器上安装 Microsoft Office 就能轻松完成多种 Excel 文件相关的处理任务,且对批注对象的属性支持非常完备。

  2. 依赖配置:如果你使用 Maven,请在 pom.xml 中添加下方代码,自动导入 Spire.XLS 到项目中。

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.cn/repository/maven-public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls</artifactId>
        <version>16.9.2</version>
    </dependency>
</dependencies>

还可以下载 Spire.XLS 安装包,解压后进行手动安装。

  1. 测试素材:本文使用了一份内容为北美人口数量前十国家的 Excel 文件,并在部分单元格中插入带有背景图片的批注。以下为素材文档图示:

Excel 素材文档图示

二、Java 提取指定单元格的批注背景图

在很多特定的业务场景中,添加批注图片时通常选择存放在固定的位置,例如:报表右上角的核验章或特定行的备注。此时,我们不需要遍历全表,而是通过获取指定单元格的方式,精准实现 Excel 批注背景图片提取。

实现思路与步骤

  • 创建 Workbook 类对象,并使用 Workbook.loadDFromFile() 方法加载素材文件。
  • 使用 Workbook.getWorksheets().get() 方法获取一个工作表。
  • 使用 Worksheet.getRange().get() 方法获取指定名称的单元格。
  • 使用 CellRange.getComment() 方法获取该单元格关联的批注对象。
  • 通过 ExcelComment.getComment().getFill().getPicture() 方法获取批注中的背景图片。
  • 通过 ImageIO.write() 方法将提取出的图片保存到本地。

完整代码展示:获取单元格 A2 批注中的背景图

import com.spire.xls.*;  
  
import javax.imageio.ImageIO;  
import java.awt.image.BufferedImage;  
import java.io.File;  
import java.io.IOException;  
  
public class ExtractComment {  
    public static void main(String[] args)throws IOException {  
        // 加载 Excel 文档  
        Workbook wb = new Workbook();  
        wb.loadFromFile("/input/示例文档.xlsx");  
  
        // 获取工作表  
        Worksheet sheet = wb.getWorksheets().get(0);  
  
        // 获取指定单元格中的批注背景图片  
        BufferedImage image = (BufferedImage) sheet.getRange().get("A2").getComment().getFill().getPicture();  
        ImageIO.write(image,"png",new File("/output/ExtractedImages.png"));  
  
    }  
}

获取到的 Excel 批注图片如下:

Java 获取 Excel 文件中指定单元格的批注图片

三、Java 批量提取工作表中的所有批注图

当 Excel 文件中包含大量图片批注,且这些批注分散在不同单元格中时,手动指定单元格的方式就显得效率低下,也缺乏可维护性。此时,更快捷做法是遍历工作表中的所有单元格,逐一判断是否存在批注,并进一步检查批注中是否包含背景图片。在完成这些条件判断的基础上,即可统一收集、提取和批量保存 Excel 批注图片,实现一键式处理。

实现思路与步骤

  • 创建 Workbook 类对象,并使用 Workbook.loadFromFile() 方法加载 Excel 文件。
  • 通过 Workbook.getWorksheets().get() 方法获取指定的工作表。
  • 调用 Worksheet.getComments().getCount() 遍历工作表中的所有批注,并判断批注是否包含背景图片。
    • 使用 ExcelComment.getFill().getPicture() 方法获取当前批注中的图片对象。
    • 通过 ExcelComment.getRow() 和 ExcelComment.getColumn() 方法获取批注所在的行号和列号,并将其转换为对应的 Excel 单元格地址。
    • 使用 ImageIO.write() 方法将提取到的批注图片保存到本地文件。

代码示例:获取素材中的所有批注图片

import com.spire.xls.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ExtractComment {
    public static void main(String[] args) throws IOException {
        // 指定文件输入输出路径
        String inputFile = "/input/示例文档.xlsx";
        String outputDir = "/output/commentpic/";

        // 加载文档
        Workbook wb = new Workbook();
        wb.loadFromFile(inputFile);

        // 获取第一个工作表
        Worksheet sheet = wb.getWorksheets().get(0);

        // 遍历批注
        for (int i = 0; i < sheet.getComments().getCount(); i++) {
            ExcelComment comment = sheet.getComments().get(i);

            // 检查批注是否包含背景图片
            if (comment.getFill() != null && comment.getFill().getPicture() != null) {
                BufferedImage image = (BufferedImage) comment.getFill().getPicture();

                // 获取批注所在的行列
                int row = comment.getRow();
                int col = comment.getColumn();

                // 转换为 Excel 单元格地址(如 H2)
                String cellAddress = getCellName(row, col);
                String fileName = "CommentImage_" + cellAddress + ".png";

                // 保存图片
                ImageIO.write(image, "png", new File(outputDir + fileName));
            }
        }
    }

    // 将行号和列号转换为 Excel 单元格地址(如 2, 8 -> H2)
    private static String getCellName(int row, int col) {
        StringBuilder columnAddress = new StringBuilder();
        int tempCol = col;
        while (tempCol > 0) {
            tempCol--;
            columnAddress.insert(0, (char) ('A' + (tempCol % 26)));
            tempCol /= 26;
        }
        return columnAddress.toString() + row;
    }
}

获取到的批注图片结果如图所示:

Java 批量获取 Excel 文件中的所有批注图片

提示:在完成批注图片提取后,某些场景下可能还需要对 Excel 中的批注显示状态进行控制,例如在导出或共享文档前临时隐藏批注。如果你有类似需求,可以参考《Java 如何设置 Excel 批注隐藏或显示》,进一步了解如何通过 Java 灵活管理批注状态。

四、 应用场景

掌握了 Excel 批注图片的提取技术后,我们可以将其应用于多种复杂的业务自动化场景中。

  1. 自动化素材归档与命名

在电商或外贸行业,业务员常将产品图存放在 Excel 批注中,而产品编号(例如 SKU)则写在同行的另一列。通过将提取出的图片直接命名为 SKU_001.png,实现图片+数据的自动关联归档,省去了后期人工核对重命名的繁琐步骤。

  1. 报表附件的批量离线化

许多审计或工程监理报表利用批注存放现场照片。通过一键提取所有工作表中的批注图,并按工作表名称建立子文件夹分类存储,可以将复杂的 Excel 转化为清晰的文件夹结构,便于离线备份和传阅。

  1. 多版本文档的视觉内容对比

在设计校对或翻译稿更新时,批注图片往往代表修改建议。利用程序自动提取新旧两个版本相同坐标下的图片进行排布对比,可以快速识别更新,大幅提升人工审阅的效率。

  1. 系统集成与数据迁移

在旧系统向云端迁移时,通过 ETL 脚本 自动提取 Excel 中的批注图并同步上传至对象存储(如 OSS),同时将返回的 URL 写入数据库,实现了图像数据的自动化迁移。

五、 结语

通过以上示例可以看到,借助 Java,我们可以轻松实现 Excel 批注图片的提取,无论是针对单个批注,还是批量处理整个工作表,都无需依赖繁琐的手动操作。这种方式不仅提升了处理效率,也让 Excel 数据的重复利用变得更加灵活。如果你在实际项目中对 Excel 文件的读写、转换或内容提取有更复杂的需求,Spire.XLS for Java 都能提供稳定而高效的解决方案。如需了解更多产品信息或获取技术支持,欢迎随时联系我们。

该文章将详细介绍如何使用Spire.Doc for Java为word文档设置行间距和字间距。

import com.spire.doc.*;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.TextRange;

import java.awt.*;
import java.io.*;

public class setSpacing {
    public static void main(String[] args)throws IOException {
        //加载示例文档
        Document document= new Document("Sample.docx");

        //添加新段落并设置段落文本和字体样式
        Paragraph para = new Paragraph(document);
        TextRange textRange1 = para.appendText("新加段落,设置行间距和字间距");
        textRange1.getCharacterFormat().setTextColor(Color.BLUE);
        textRange1.getCharacterFormat().setFontSize(15);

        //设置段前段后间距
        para.getFormat().setBeforeAutoSpacing(false);
        para.getFormat().setBeforeSpacing(10);
        para.getFormat().setAfterAutoSpacing(false);
        para.getFormat().setAfterSpacing(10);

        //设置字间距
        for (DocumentObject object :(Iterable<DocumentObject>)para.getChildObjects())
        {
            TextRange textRange= (TextRange) object;
            textRange.getCharacterFormat().setCharacterSpacing(3f);
        }

        //插入新加段落
        document.getSections().get(0).getParagraphs().insert(1, para);

        //保存文档
        document.saveToFile("result.docx", FileFormat.Docx);

    }
}

效果图:

Java 设置 Word 行间距和字间距

本文将介绍如何使用Spire.Presentation for .NET给PowerPoint文档添加数字签名或删除PowerPoint文档中的现有数字签名。

添加数字签名

C#
using Spire.Presentation;
using System;

namespace AddDigitalSignature
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建Presentation实例
            Presentation ppt = new Presentation();
			
	   //加载PowerPoint文档
            ppt.LoadFromFile("Input.pptx");

            //添加数字签名
            ppt.AddDigitalSignature("gary.pfx", "e-iceblue", "test", DateTime.Now);

            //保存结果文档
            ppt.SaveToFile("AddDigitalSignature_result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("AddDigitalSignature_result.pptx");

            //释放
            ppt.Dispose();
        }
    }
}
VB.NET
Imports Spire.Presentation
Imports System


Namespace AddDigitalSignature
    Class Program
        Private Shared Sub Main(ByVal args As String())
            '加载ppt文档
            Dim ppt As Presentation = New Presentation()
            ppt.LoadFromFile("Input.pptx")
             '添加签名
            ppt.AddDigitalSignature("gary.pfx", "e-iceblue", "test", Date.Now)
             '保存
            ppt.SaveToFile("AddDigitalSignature.pptx", FileFormat.Pptx2013)
            '释放
            ppt.Dispose()
        End Sub
    End Class
End Namespace

结果文档:

C#/VB.NET 添加或删除 PowerPoint 数字签名

删除数字签名

C#
using Spire.Presentation;
using System;
using System.Security.Cryptography.X509Certificates;

namespace RemoveDigitalSignature
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建Presentation实例
            Presentation ppt = new Presentation();
            //加载PowerPoint文档
            ppt.LoadFromFile("AddDigitalSignature.pptx");

            //判断文档中是否有数字签名
            if (ppt.IsDigitallySigned == true)
            {
                //删除所有数字签名
                ppt.RemoveAllDigitalSignatures();
            }

            //保存结果文档
            ppt.SaveToFile("RemoveDigitalSignature.pptx", FileFormat.Pptx2013);

        }
    }
}
VB.NET
Imports Spire.Presentation
Imports System
Imports System.Security.Cryptography.X509Certificates

Namespace RemoveDigitalSignature
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Dim ppt As Presentation = New Presentation()
            ppt.LoadFromFile("AddDigitalSignature.pptx")

            If ppt.IsDigitallySigned = True Then
                ppt.RemoveAllDigitalSignatures()
            End If

            ppt.SaveToFile("RemoveDigitalSignature.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

结果文档:

C#/VB.NET 添加或删除 PowerPoint 数字签名

PPT中的动画可分为内置动画及自定义动画。设置内置动画效果可参考这篇文章,本文介绍使用Spire.Presentation for .NET来实现自定义动画效果。

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

namespace CustomAnimation
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)
            Presentation ppt = new Presentation();
            ISlide slide = ppt.Slides[0];//获取第一页空白幻灯片

            //添加形状(指定形状坐标、大小及相关格式设置)
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, new RectangleF(100, 50, 180, 180));
            shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient;
            shape.Fill.Gradient.GradientStops.Append(0, KnownColors.SkyBlue);
            shape.Fill.Gradient.GradientStops.Append(1, KnownColors.Pink);
            shape.ShapeStyle.LineColor.Color = Color.White;

            //给形状设置动画效果
            AnimationEffect effect = ppt.Slides[0].Timeline.MainSequence.AddEffect(shape, AnimationEffectType.PathUser);
            CommonBehaviorCollection common = effect.CommonBehaviorCollection;
            AnimationMotion motion = (AnimationMotion)common[0];
            motion.Origin = AnimationMotionOrigin.Layout;
            motion.PathEditMode = AnimationMotionPathEditMode.Relative;
            MotionPath moinPath = new MotionPath();
            moinPath.Add(MotionCommandPathType.MoveTo, new PointF[] { new PointF(0, 0) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.18f, 0.18f) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(-0.1f, 0.2f) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.LineTo, new PointF[] { new PointF(0.25f, 0.2f) }, MotionPathPointsType.CurveAuto, true);
            moinPath.Add(MotionCommandPathType.End, new PointF[] { }, MotionPathPointsType.CurveStraight, true);
            motion.Path = moinPath;

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

Namespace CustomAnimation
	Class Program
		Private Shared Sub Main(args As String())
			'创建一个幻灯片文档(新建的文档已默认包含一页幻灯片)
			Dim ppt As New Presentation()
            '获取第一页空白幻灯片
			Dim slide As ISlide = ppt.Slides(0)
			
			'添加形状(指定形状坐标、大小及相关格式设置)
			Dim shape As IAutoShape = slide.Shapes.AppendShape(ShapeType.FivePointedStar, New RectangleF(100, 50, 180, 180))
			shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Gradient
			shape.Fill.Gradient.GradientStops.Append(0, KnownColors.SkyBlue)
			shape.Fill.Gradient.GradientStops.Append(1, KnownColors.Pink)
			shape.ShapeStyle.LineColor.Color = Color.White

			'给形状设置动画效果
			Dim effect As AnimationEffect = ppt.Slides(0).Timeline.MainSequence.AddEffect(shape, AnimationEffectType.PathUser)
			Dim common As CommonBehaviorCollection = effect.CommonBehaviorCollection
			Dim motion As AnimationMotion = DirectCast(common(0), AnimationMotion)
			motion.Origin = AnimationMotionOrigin.Layout
			motion.PathEditMode = AnimationMotionPathEditMode.Relative
			Dim moinPath As New MotionPath()
			moinPath.Add(MotionCommandPathType.MoveTo, New PointF() {New PointF(0, 0)}, MotionPathPointsType.CurveAuto, True)
			moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(0.18F, 0.18F)}, MotionPathPointsType.CurveAuto, True)
			moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(-0.1F, 0.2F)}, MotionPathPointsType.CurveAuto, True)
			moinPath.Add(MotionCommandPathType.LineTo, New PointF() {New PointF(0.25F, 0.2F)}, MotionPathPointsType.CurveAuto, True)
			moinPath.Add(MotionCommandPathType.[End], New PointF() {}, MotionPathPointsType.CurveStraight, True)
			motion.Path = moinPath

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

自定义动画效果:

C#/VB.NET 自定义 PPT 动画效果