PPTX

样式与主题

在幻灯片中应用配色方案、主题颜色和一致的样式

使用填充、轮廓和配色方案在演示文稿中应用一致的样式。

形状的纯色填充

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

new Shape({
    x: 1,
    y: 1,
    width: 5,
    height: 2,
    fill: { type: "solid", color: "2E74B5" },
    text: "Blue shape",
    paragraphs: [
        new Paragraph({
            children: [new TextRun({ text: "Blue background", color: "FFFFFF", fontSize: 20 })],
        }),
    ],
});

渐变填充

带角度的线性渐变:

new Shape({
    x: 1,
    y: 1,
    width: 6,
    height: 3,
    fill: {
        type: "gradient",
        stops: [
            { position: 0, color: "0D47A1" },
            { position: 50, color: "1976D2" },
            { position: 100, color: "42A5F5" },
        ],
        angle: 45,
    },
});

路径渐变(径向):

new Shape({
    x: 1,
    y: 1,
    width: 5,
    height: 5,
    geometry: "ellipse",
    fill: {
        type: "gradient",
        stops: [
            { position: 0, color: "FFFFFF" },
            { position: 100, color: "1565C0" },
        ],
        path: "circle",
    },
});

无填充(透明)

new Shape({
    x: 1,
    y: 1,
    width: 5,
    height: 2,
    fill: { type: "noFill" },
    outline: { color: "2E74B5", width: 2 },
    text: "Transparent shape with border",
});

轮廓

new Shape({
    x: 1,
    y: 1,
    width: 5,
    height: 3,
    fill: { type: "solid", color: "E3F2FD" },
    outline: { color: "1565C0", width: 2 },
    text: "Bordered shape",
});

配色方案提示

定义一致的调色板并复用它:

const colors = {
    primary: "2E74B5",
    secondary: "70AD47",
    accent: "ED7D31",
    dark: "1F3864",
    light: "D6E4F0",
    white: "FFFFFF",
};

new Shape({
    fill: { type: "solid", color: colors.primary },
    paragraphs: [
        new Paragraph({
            children: [
                new TextRun({ text: "Title", color: colors.white, bold: true, fontSize: 24 }),
            ],
        }),
    ],
});

背景样式

在幻灯片级别应用背景样式:

import { Slide } from "@office-open/pptx";

// 纯色背景
new Slide({
    background: { type: "solid", color: "1F3864" },
    children: [],
});

// 渐变背景
new Slide({
    background: {
        type: "gradient",
        stops: [
            { position: 0, color: "0D47A1" },
            { position: 100, color: "42A5F5" },
        ],
        angle: 135,
    },
    children: [],
});
Copyright © 2026