跳到主要内容
Office Open

PPTX

样式与主题

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

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

#形状的纯色填充

ts
import { generatePresentation } from "@office-open/pptx";
JSON
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "13.2cm",
            "height": "5.3cm",
            "textBody": {
              "text": "Blue shape",
              "paragraphs": [
                {
                  "children": [
                    {
                      "text": "Blue background",
                      "fill": "FFFFFF",
                      "size": 20
                    }
                  ]
                }
              ]
            },
            "properties": {
              "fill": {
                "type": "solid",
                "color": "2E74B5"
              }
            }
          }
        }
      ]
    }
  ]
}

#渐变填充

带角度的线性渐变:

JSON
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "6.6cm",
            "properties": {
              "fill": {
                "type": "gradient",
                "stops": [
                  {
                    "position": 0,
                    "color": "0D47A1"
                  },
                  {
                    "position": 50,
                    "color": "1976D2"
                  },
                  {
                    "position": 100,
                    "color": "42A5F5"
                  }
                ],
                "angle": 45
              }
            }
          }
        }
      ]
    }
  ]
}

路径渐变(径向):

JSON
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "10.6cm",
            "height": "10.6cm",
            "properties": {
              "geometry": "ellipse",
              "fill": {
                "type": "gradient",
                "stops": [
                  {
                    "position": 0,
                    "color": "FFFFFF"
                  },
                  {
                    "position": 100,
                    "color": "1565C0"
                  }
                ],
                "path": "circle"
              }
            }
          }
        }
      ]
    }
  ]
}

#无填充(透明)

JSON
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "13.2cm",
            "height": "5.3cm",
            "properties": {
              "fill": {
                "type": "none"
              },
              "outline": {
                "color": "2E74B5",
                "width": 2
              }
            }
          }
        }
      ]
    }
  ]
}

#轮廓

JSON
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "13.2cm",
            "height": "6.6cm",
            "properties": {
              "fill": {
                "type": "solid",
                "color": "E3F2FD"
              },
              "outline": {
                "color": "1565C0",
                "width": 2
              }
            }
          }
        }
      ]
    }
  ]
}

#配色方案提示

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

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

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

generatePresentation({
  slides: [
    {
      children: [
        {
          shape: {
            x: "1.3cm",
            y: "1.3cm",
            width: "13.2cm",
            height: "5.3cm",
            properties: {
              fill: { type: "solid", color: colors.primary },
            },
            textBody: {
              paragraphs: [
                {
                  children: [{ text: "Title", fill: colors.white, bold: true, size: 24 }],
                },
              ],
            },
          },
        },
      ],
    },
  ],
});

#背景样式

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

JSON
{
  "slides": [
    {
      "background": {
        "fill": "1F3864"
      },
      "children": []
    }
  ]
}
JSON
{
  "slides": [
    {
      "background": {
        "fill": {
          "type": "gradient",
          "stops": [
            {
              "position": 0,
              "color": "0D47A1"
            },
            {
              "position": 100,
              "color": "42A5F5"
            }
          ],
          "angle": 135
        }
      },
      "children": []
    }
  ]
}