Install
openclaw skills install html2pptx-shapeHTML 转 PPTX 形状转换器 — 将 HTML 幻灯片转换为完全可编辑的 PPTX,自动内嵌外部 CSS,保留 CSS 样式、布局,映射为 PPTX 原生形状(矩形/文本框/图片等)
openclaw skills install html2pptx-shape将 HTML 幻灯片转换为 完全可编辑的 PPTX,核心特性:
<link> 引用的 CSS 文件嵌入到 <style> 标签cd /Users/panda/.openclaw/workspace/skills/html2pptx-shape
pip3 install -r requirements.txt
playwright install chromium
# 转换 HTML 文件(自动内嵌外部 CSS)
python3 index.py <input.html> [output.pptx]
# 示例
python3 index.py examples/demo.html
python3 index.py my-presentation.html my-output.pptx
| 项目 | 说明 |
|---|---|
| 文件名 | <input>_converted.pptx(默认)或指定名称 |
| 格式 | PPTX (Office Open XML) |
| 比例 | 16:9 widescreen |
| 可编辑性 | ✅ 所有文字/形状可编辑 |
自动将外部 CSS 文件嵌入到 HTML 的 <style> 标签中:
<!-- 转换前 -->
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="theme.css">
<!-- 转换后 -->
<style>
/* styles.css 内容 */
/* theme.css 内容 */
</style>
支持:
<link> 标签:root 和任何选择器中的定义)| CSS 属性 | PPTX 映射 | 支持度 |
|---|---|---|
color | 文字颜色 | ✅ |
background-color | 填充颜色 | ✅ |
background (gradient) | 渐变填充 | ⚠️ 转为纯色 |
font-family | 字体 | ✅ |
font-size | 字号 | ✅ |
font-weight | 字重 | ✅ |
text-align | 对齐方式 | ✅ |
border | 边框 | ✅ |
border-radius | 圆角矩形 | ✅ |
box-shadow | 阴影 | ✅ |
opacity | 透明度 | ✅ |
width/height | 尺寸 | ✅ |
position: absolute | 绝对定位 | ✅ |
| HTML 元素 | PPTX 形状 | 说明 |
|---|---|---|
<div> | Rectangle | 矩形背景/容器 |
<p>, <h1>-<h6> | TextBox | 文本框,保留字体/颜色/对齐 |
<img> | Picture | 图片,支持 base64/URL/本地文件 |
<svg> | Freeform | SVG 路径转 PPTX 自由形状(简化) |
<span> | (内联) | 文本格式化,不创建独立形状 |
<ul>, <ol> | TextBox | 列表文本框,保留项目符号 |
<style> 标签section.slide,每页创建一张幻灯片html-ppt 生成的 HTML 演示文稿转为可编辑 PPTXpython3 index.py examples/demo.html
# 输出:examples/demo_converted.pptx
python3 index.py my-presentation.html
# 自动嵌入 style.css, theme.css 等外部文件
# 输出:my-presentation_converted.pptx
python3 index.py input.html output.pptx
from index import run
result = run(["./examples/demo.html"])
print(f"Generated: {result['output_file']}")
print(f"Slides: {result['slides_count']}")
html2pptx-shape/
├── SKILL.md (本文档)
├── README.md (快速入门)
├── index.py (核心转换逻辑)
├── requirements.txt (Python 依赖)
├── scripts/
│ ├── embed-css.py (独立 CSS 嵌入工具)
│ ├── debug-convert.py (调试脚本)
│ ├── check-inline.py (样式检查脚本)
│ └── debug-vars.py (变量调试脚本)
└── examples/
├── demo.html (示例 HTML - 4 页)
├── demo_converted.pptx (生成的 PPTX)
├── external-css.html (外部 CSS 测试)
├── external-css_converted.pptx
├── styles.css
└── theme.css
# 1. 用 html-ppt 生成 HTML 演示文稿
# (使用 html-ppt skill 创建 HTML)
# 2. 转换为可编辑 PPTX
python3 index.py my-deck/index.html
# 3. 在 PowerPoint 中打开并编辑
open my-deck/index_converted.pptx
# 情况 A: HTML 引用外部 CSS
# index.html 中有:<link rel="stylesheet" href="style.css">
# 直接转换,自动嵌入 CSS
python3 index.py index.html
# 情况 B: 想先内嵌 CSS 再转换
python3 scripts/embed-css.py index.html
python3 index.py index_embedded.html
| 限制 | 说明 | 建议 |
|---|---|---|
| CSS 动画 | 不支持(转换为静态) | 使用截图版保留视觉效果 |
| CSS Grid/Flex | 简化为绝对定位 | 检查布局是否正确 |
| 外部字体 | 回退到系统字体 | 确保系统有相应字体 |
::before/::after | PPTX 不支持伪元素 | 忽略警告 |
background-clip: text | 渐变文字转纯色 | 手动在 PPTX 中添加渐变 |
| 复杂 SVG | 降级为占位符 | 简化 SVG 或转为图片 |
# Python 依赖
pip3 install python-pptx beautifulsoup4 pillow requests cssutils premailer
# Playwright 浏览器(用于截图功能)
playwright install chromium
⚠️ CSS file not found: xxx.css
原因: 相对路径无法解析
解决:
scripts/embed-css.py 先内嵌 CSS<style> 标签中原因: CSS 选择器太复杂或使用了不支持的属性
解决:
style="..." 替代原因: CSS Grid/Flex 布局被简化
解决:
position: absolute 替代| 特性 | html2pptx-shape | html-to-pptx |
|---|---|---|
| CSS 内嵌 | ✅ 自动 | ⚠️ 需要预处理器 |
| CSS 变量解析 | ✅ 完整支持 | ⚠️ 部分支持 |
| 形状映射 | ✅ 原生 PPTX 形状 | ⚠️ 简化文本框 |
| 可编辑性 | ✅ 完全可编辑 | ✅ 完全可编辑 |
| 文件大小 | 小 (30-50KB) | 小 (30-50KB) |
| 截图高保真 | ❌ | ✅ 支持 |
MIT
老 6 🎯