產生、編輯和讀取 PowerPoint 簡報。使用 PptxGenJS 從頭建立(封面、目錄、內容、章節分隔、摘要投影片),透過 XML 工作流程編輯現有 PPTX,或使用 markitdown 擷取文字。觸發詞:PPT、PPTX、PowerPoint、簡報、投影片、slide、slides。
PPTX 產生器與編輯器
概述
此技能處理所有 PowerPoint 任務:讀取/分析現有簡報、透過 XML 操作編輯基於範本的簡報,以及使用 PptxGenJS 從頭建立簡報。它包含完整的設計系統(色板、字型、樣式配方)以及每種投影片類型的詳細指引。
快速參考
| 任務 | 方法 |
|---|---|
| 讀取/分析內容 | python -m markitdown presentation.pptx |
| 編輯或從範本建立 | 請參閱編輯簡報 |
| 從頭建立 | 請參閱下方從頭建立工作流程 |
| 項目 | 值 |
|---|---|
| 尺寸 | 10" x 5.625" (LAYOUT_16x9) |
| 顏色 | 6 字元十六進位,不含 #(例如 "FF0000") |
| 英文字型 | Arial(預設)或核准的替代字型 |
| 中文字型 | Microsoft YaHei |
| 頁碼徽章位置 | x: 9.3", y: 5.1" |
| 主題鍵 | primary、secondary、accent、light、bg |
| 形狀 | RECTANGLE、OVAL、LINE、ROUNDED_RECTANGLE |
| 圖表 | BAR、LINE、PIE、DOUGHNUT、SCATTER、BUBBLE、RADAR |
參考檔案
| 檔案 | 內容 |
|---|---|
| slide-types.md | 5 種投影片頁面類型(封面、目錄、章節分隔、內容、摘要)+ 其他版面配置模式 |
| design-system.md | 色板、字型參考、樣式配方(銳利/柔和/圓角/藥丸)、排版與間距 |
| editing.md | 基於範本的編輯工作流程、XML 操作、格式化規則、常見陷阱 |
| pitfalls.md | QA 流程、常見錯誤、關鍵的 PptxGenJS 陷阱 |
| pptxgenjs.md | 完整的 PptxGenJS API 參考 |
讀取內容
# 文字擷取
python -m markitdown presentation.pptx
從頭建立 — 工作流程
當沒有範本或參考簡報時使用。
步驟 1:研究與需求
搜尋以了解使用者需求 — 主題、受眾、目的、語氣、內容深度。
步驟 2:選擇色板與字型
使用色板參考選擇符合主題與受眾的色板。使用字型參考選擇字型搭配。
步驟 3:選擇設計風格
使用樣式配方選擇符合簡報語氣的視覺風格(銳利、柔和、圓角或藥丸)。
步驟 4:規劃投影片大綱
將每張投影片分類為5 種頁面類型中的一種。規劃每張投影片的內容與版面配置。確保視覺多樣性 — 不要在投影片間重複相同的版面配置。
步驟 5:產生投影片 JS 檔案
在 slides/ 目錄中為每張投影片建立一個 JS 檔案。每個檔案必須匯出一個同步的 createSlide(pres, theme) 函式。遵循投影片輸出格式以及 slide-types.md 中特定類型的指引。如果有的話,使用子代理程式同時產生最多 5 張投影片。
告訴每個子代理程式:
- 檔案命名:
slides/slide-01.js、slides/slide-02.js等。 - 圖片放在:
slides/imgs/ - 最終 PPTX 放在:
slides/output/ - 尺寸:10" x 5.625" (LAYOUT_16x9)
- 字型:中文 = Microsoft YaHei,英文 = Arial(或核准的替代字型)
- 顏色:6 字元十六進位,不含 #(例如
"FF0000") - 必須使用主題物件合約(請參閱主題物件合約)
- 必須遵循 PptxGenJS API 參考
步驟 6:編譯成最終 PPTX
建立 slides/compile.js 以合併所有投影片模組:
// slides/compile.js
const pptxgen = require('pptxgenjs');
const pres = new pptxgen();
pres.layout = 'LAYOUT_16x9';
const theme = {
primary: "22223b", // 用於背景/文字的深色
secondary: "4a4e69", // 次要強調色
accent: "9a8c98", // 強調色
light: "c9ada7", // 淺色強調
bg: "f2e9e4" // 背景色
};
for (let i = 1; i <= 12; i++) { // 根據需要調整數量
const num = String(i).padStart(2, '0');
const slideModule = require(`./slide-${num}.js`);
slideModule.createSlide(pres, theme);
}
pres.writeFile({ fileName: './output/presentation.pptx' });
執行:cd slides && node compile.js
步驟 7:QA(必要)
請參閱QA 流程。
輸出結構
slides/
├── slide-01.js # 投影片模組
├── slide-02.js
├── ...
├── imgs/ # 投影片中使用的圖片
└── output/ # 最終成品
└── presentation.pptx
投影片輸出格式
每張投影片是一個完整、可執行的 JS 檔案:
// slide-01.js
const pptxgen = require("pptxgenjs");
const slideConfig = {
type: 'cover',
index: 1,
title: '簡報標題'
};
// 必須是同步(非 async)
function createSlide(pres, theme) {
const slide = pres.addSlide();
slide.background = { color: theme.bg };
slide.addText(slideConfig.title, {
x: 0.5, y: 2, w: 9, h: 1.2,
fontSize: 48, fontFace: "Arial",
color: theme.primary, bold: true, align: "center"
});
return slide;
}
// 獨立預覽 - 使用投影片專屬檔名
if (require.main === module) {
const pres = new pptxgen();
pres.layout = 'LAYOUT_16x9';
const theme = {
primary: "22223b",
secondary: "4a4e69",
accent: "9a8c98",
light: "c9ada7",
bg: "f2e9e4"
};
createSlide(pres, theme);
pres.writeFile({ fileName: "slide-01-preview.pptx" });
}
module.exports = { createSlide, slideConfig };
主題物件合約(強制)
編譯腳本傳遞一個主題物件,包含以下確切鍵:
| 鍵 | 用途 | 範例 |
|---|---|---|
theme.primary |
最深色,標題 | "22223b" |
theme.secondary |
深色強調,內文 | "4a4e69" |
theme.accent |
中間色調強調 | "9a8c98" |
theme.light |
淺色強調 | "c9ada7" |
theme.bg |
背景色 | "f2e9e4" |
絕對不要使用其他鍵名,例如 background、text、muted、darkest、lightest。
頁碼徽章(必要)
所有投影片除了封面頁都必須在右下角包含頁碼徽章。
- 位置:x: 9.3", y: 5.1"
- 只顯示目前數字(例如
3或03),不要顯示 "3/12" - 使用色板顏色,保持低調
圓形徽章(預設)
slide.addShape(pres.shapes.OVAL, {
x: 9.3, y: 5.1, w: 0.4, h: 0.4,
fill: { color: theme.accent }
});
slide.addText("3", {
x: 9.3, y: 5.1, w: 0.4, h: 0.4,
fontSize: 12, fontFace: "Arial",
color: "FFFFFF", bold: true,
align: "center", valign: "middle"
});
藥丸徽章
slide.addShape(pres.shapes.ROUNDED_RECTANGLE, {
x: 9.1, y: 5.15, w: 0.6, h: 0.35,
fill: { color: theme.accent },
rectRadius: 0.15
});
slide.addText("03", {
x: 9.1, y: 5.15, w: 0.6, h: 0.35,
fontSize: 11, fontFace: "Arial",
color: "FFFFFF", bold: true,
align: "center", valign: "middle"
});
相依套件
pip install "markitdown[pptx]"— 文字擷取npm install -g pptxgenjs— 從頭建立npm install -g react-icons react react-dom sharp— 圖示(選用)






