PPTX

链接

为形状和文本添加超链接以实现交互式导航

为形状或文本片段添加可点击的超链接,用于网页导航、邮件链接或幻灯片内部引用。

形状上的超链接

使整个形状可点击:

import { Slide, Shape, Paragraph, TextRun } from "@office-open/pptx";

new Slide({
    children: [
        new Shape({
            x: 1,
            y: 1,
            width: 4,
            height: 1,
            text: "Visit our website",
            paragraphs: [
                new Paragraph({
                    children: [
                        new TextRun({ text: "Visit our website", color: "0563C1", underline: {} }),
                    ],
                }),
            ],
            hyperlink: {
                url: "https://example.com",
                tooltip: "Go to example.com",
            },
        }),
    ],
});

文本片段上的超链接

为特定文本部分应用超链接:

new Shape({
    x: 1,
    y: 1,
    width: 6,
    height: 3,
    paragraphs: [
        new Paragraph({
            children: [
                new TextRun({ text: "For more info, visit " }),
                new TextRun({
                    text: "our documentation",
                    color: "0563C1",
                    underline: {},
                    hyperlink: {
                        url: "https://docs.example.com",
                        tooltip: "Open documentation",
                    },
                }),
                new TextRun({ text: " for details." }),
            ],
        }),
    ],
});

邮件链接

使用 mailto: URL 创建邮件超链接:

new TextRun({
    text: "Contact Support",
    color: "0563C1",
    underline: {},
    hyperlink: {
        url: "mailto:support@example.com",
        tooltip: "Send email to support",
    },
});

幻灯片内部链接

导航到演示文稿中的特定幻灯片:

new Shape({
    x: 1,
    y: 4,
    width: 3,
    height: 0.8,
    text: "Go to Summary",
    hyperlink: {
        slide: 3, // 导航到幻灯片索引 3(从 0 开始)
        tooltip: "Jump to summary slide",
    },
});

超链接选项

属性类型说明
urlstring外部 URL 或 mailto: 链接
slidenumber目标幻灯片索引(从 0 开始)
tooltipstring悬停时显示的提示文字

注意:使用 urlslide 其中之一,不要同时使用两者。

Copyright © 2026