aardio 文档

填写既有页的文字与空占位符

从 0.17.0 起,fsys.openXml.pptx.editor 可以按形状或占位符替换全部文字。适合固定模板和覆盖某个文本框;如果要只替换 {{Name}} 并保留其他运行格式,使用 replaceText。

先读,再填

先用 pptx.read(path,{includeStructure=true}) 定位实际页序、版式和 pages[].placeholders。同一编辑会话中,使用 doc.listPlaceholders(page) 查看最新形状,不用重新打开源件。形状 id 和占位符索引不是同一编号。图片占位符 type="pic" 不写文字,应使用 空图片占位符填充。

以下假定模板第 1 页已存在标题和索引 1 的内容占位符。运行后第 2 页是填充副本,示例页保留:

import fsys.openXml.pptx;
import fsys.openXml.pptx.editor;
var input="/template.pptx";
var before,err=fsys.openXml.pptx.read(input,{includeStructure=true;includeNotes=false});
if(!before) return null,err;
var slots=before.pages[[1]][["placeholders"]];
if(!#slots) return null,"第 1 页没有实际占位符";
var doc,err=fsys.openXml.pptx.editor.open(input);
if(!doc) return null,err;
var page,err=doc.copySlide(1);
if(!page){doc.close();return null,err;}
var n,err=doc.setPlaceholderText(page.index,"title","项目进展");
if(n===null){doc.close();return null,err;}
var n,err=doc.setPlaceholderText(page.index,{index=1},["完成结构读取","验证模板填充"]);
if(n===null){doc.close();return null,err;}
var path,err=doc.save("/filled-template.pptx");
doc.close();
if(!path) return null,err;
return fsys.openXml.pptx.read(path,{includeStructure=true;includeNotes=false});

接口与选择规则

格式与安全边界

Markdown 格式