ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

OfficeCLI 幻灯片文本框完全指南:对齐、列表、富文本与多语言排版的命令行实战

2026/10/1 16:50:37 拓冰建站 浏览量
OfficeCLI 幻灯片文本框完全指南:对齐、列表、富文本与多语言排版的命令行实战 CLIAI 应用MCP 服务【免费下载链接】OfficeCLIOfficeCLI is the first and best Office suite purpose-built for AI agents to read, edit, and automate Word, Excel, and PowerPoint files. Free, open-source, single binary, no Office installation required.项目地址https://gitcode.com/GitHub_Trending/of/OfficeCLI点击查看免费下载这篇指南以仓库中的实战示例 textboxes-basic.md 为骨架完整拆解如何用 OfficeCLI 通过officecli add/set命令在 PowerPoint 幻灯片中构建四种典型文本框场景水平对齐、多段落与项目符号/编号列表、单段落内的富文本 run加粗/斜体/下划线/删除线/上下标、以及多脚本字体Latin East Asian与垂直对齐/内边距排版。读完你不仅能逐条复现 4 页示例幻灯片还能理解textbox/paragraph/run三种元素类型在 OOXML 中的对应关系掌握list、level、valign、margin、font.latin/font.ea等关键属性的取值与底层写入行为并学会用query/get逆向检查生成结果。一、示例三件套与运行环境本示例由三个文件协同构成均位于 examples/ppt/textboxestextboxes-basic.sh— Shell 脚本逐条调用officecliCLI 命令构建整套 4 页演示文稿textboxes-basic.py— 与 Shell 等价的 Python SDK 版本officecli-sdk通过一次doc.batch(...)批量往返生成同一份文件textboxes-basic.md— 文档即本文骨架将每页幻灯片映射到它演示的特性textboxes-basic.pptx— 生成产物4 页幻灯片覆盖对齐、多段落列表、样式化 run、多语言字体与布局。重新生成演示文稿只需两步cd examples/ppt bash textboxes/textboxes-basic.sh # → textboxes/textboxes-basic.pptx在运行之前先确认officecli命令已在 PATH 中。仓库根目录提供了跨平台安装脚本install.shmacOS/Linux、install.ps1Windows PowerShell以及面向开发者的 dev-install.sh本地源码构建入口为 officecli.csprojdotnet build后使用src/officecli/bin/...下的二进制。安装完成后用officecli --version验证版本。值得留意的是textboxes-basic.sh 刻意没有set -e。与 Python SDK 版本的doc.batch一样脚本对 UNSUPPORTED props 这类前向兼容警告退出码 2保持容忍继续构建直至产出完整文档。这一点对阅读脚本输出很有用——看到警告不一定意味着失败。二、Slide 1 — 水平对齐align第一页的核心问题是同一段长文本在四个文本框中分别以left/center/right/justify四种对齐方式呈现形成直观对比。officecli create textboxes-basic.pptx officecli open textboxes-basic.pptx officecli add textboxes-basic.pptx / --type slide LOREMLorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus lacinia odio vitae vestibulum vestibulum. # alignleft (default) officecli add textboxes-basic.pptx /slide[1] --type textbox \ --prop x0.5in --prop y1.3in --prop width12in --prop height1.3in \ --prop fillF1FAEE --prop text[alignleft] $LOREM --prop size14 \ --prop alignleft # aligncenter officecli add textboxes-basic.pptx /slide[1] --type textbox \ --prop x0.5in --prop y2.8in --prop width12in --prop height1.3in \ --prop fillF1FAEE --prop text[aligncenter] $LOREM --prop size14 \ --prop aligncenter # alignright officecli add textboxes-basic.pptx /slide[1] --type textbox \ --prop x0.5in --prop y4.3in --prop width12in --prop height1.3in \ --prop fillF1FAEE --prop text[alignright] $LOREM --prop size14 \ --prop alignright # alignjustify officecli add textboxes-basic.pptx /slide[1] --type textbox \ --prop x0.5in --prop y5.8in --prop width12in --prop height1.3in \ --prop fillF1FAEE --prop text[alignjustify] $LOREM --prop size14 \ --prop alignjustify本页特性--type textboxshape的别名——在 OOXML 中二者都是文本框、alignleft、center、right、justify、fill、text、size、x/y/width/height。从源码看--type textbox的别名语义在 PowerPointHandler.Add.cs 中可以看到分派逻辑shape or textbox when properties ! null properties.ContainsKey(formula) AddEquation(...), ... shape or textbox AddShape(parentPath, index, properties ?? new(), type.ToLowerInvariant()),即textbox与shape走的是同一条AddShape路径带formula属性时二者同样会转向AddEquation生成公式形状。进一步在 PowerPointHandler.Add.Shape.cs 中elementTypeHint textbox被用来确定生成的是文本框风格无几何预设、默认矩形正文还是真正的图形形状。这也解释了 schema 中 textbox.json 的注记Alias for shape — both route to AddShape且其路径映射为/slide[N]/shape[M]——也就是说即使你写--type textbox后续寻址依然通过/slide[N]/shape[1]进行。属性速查来自 textbox.json属性类型/取值说明alignleft|center|right|justify水平对齐默认 leftfill颜色hex 如F1FAEE或 scheme 名如accent1文本框背景填充别名backgroundx/y长度0.5in、2cm、72pt文本框位置readback 为 cmwidth/height长度文本框尺寸size字号14、14pt、10.5ptAdd/Set 时转发到首个 run读取用effective.sizebold/italic/color布尔/颜色同样转发到首个 run读取走effective.*autoFitnone|normal|shape文本框自动适应模式别名autofit注意size、bold、color在 textbox 层级是写直达、读绕行写入时作用于第一个 run 的字符属性读取时请使用effective.size、effective.color、effective.bold继承自 placeholder→layout→master→presentation 默认值设置后即被显式值抑制。三、Slide 2 — 多段落 项目符号 / 编号列表第二页演示先搭段落、再整体套用列表样式的经典模式左侧是咖啡冲煮步骤的项目符号列表右侧是发布检查清单的编号列表外加一条通过level1缩进一层级的子项。officecli add textboxes-basic.pptx / --type slide # 项目符号列表 —— 先添加标题段落再追加正文段落 # 最后用 set 以 listbullet 把全部段落变成项目符号。 officecli add textboxes-basic.pptx /slide[2] --type textbox \ --prop x0.5in --prop y1.2in --prop width6in --prop height4in \ --prop textCoffee preparation steps \ --prop boldtrue --prop size18 --prop color1D3557 officecli add textboxes-basic.pptx /slide[2]/shape[1] --type paragraph \ --prop textGrind beans to medium-fine officecli add textboxes-basic.pptx /slide[2]/shape[1] --type paragraph \ --prop textHeat water to 93°C officecli add textboxes-basic.pptx /slide[2]/shape[1] --type paragraph \ --prop textBloom 30s with 2× coffee weight officecli add textboxes-basic.pptx /slide[2]/shape[1] --type paragraph \ --prop textPour remaining water in spirals officecli add textboxes-basic.pptx /slide[2]/shape[1] --type paragraph \ --prop textTotal brew time: 3-4 minutes # 在 shape 层级把全部段落变为项目符号 officecli set textboxes-basic.pptx /slide[2]/shape[1] --prop listbullet # 编号列表 —— 同样的模式 officecli add textboxes-basic.pptx /slide[2] --type textbox \ --prop x7in --prop y1.2in --prop width6in --prop height4in \ --prop textRelease checklist \ --prop boldtrue --prop size18 --prop color1D3557 officecli add textboxes-basic.pptx /slide[2]/shape[2] --type paragraph \ --prop textRun tests officecli add textboxes-basic.pptx /slide[2]/shape[2] --type paragraph \ --prop textTag the release officecli add textboxes-basic.pptx /slide[2]/shape[2] --type paragraph \ --prop textPush to registry officecli add textboxes-basic.pptx /slide[2]/shape[2] --type paragraph \ --prop textAnnounce in #releases officecli set textboxes-basic.pptx /slide[2]/shape[2] --prop listnumbered # 子项level1 将步骤嵌套一级 officecli add textboxes-basic.pptx /slide[2]/shape[2] --type paragraph \ --prop text(verify checksum) --prop level1 officecli set textboxes-basic.pptx /slide[2]/shape[2] --prop listnumbered本页特性--type paragraph向父 shape 追加一个段落、listbullet、numbered—— 通过set在 shape 层级应用、level缩进深度0 顶层1 缩进一级以此类推。paragraph 的类型语义根据 paragraph.json--type paragraph向 shape 的 TextBody 追加一个a:p元素路径为/slide[N]/shape[M]/p[K]支持别名p、para。其常用属性align同上四种取值别名alignment/halignlevel列表缩进级别 0–8a:pPr/lvllist段落项目符号样式命名预设bullet、dash、arrow、check、star、none也接受字面项目符号字符numbered/alpha/roman等映射到自动编号方案别名bulletbold/italic/color/size/lang段落级默认 run 属性写入defRPrCT_TextCharacterProperties被段落内未显式覆盖的 run 继承当所有 run 取值一致时dump 会将其折叠到段落层。需要理解的关键点是list既可以像示例那样通过set在shape 层级一次应用到该 shape 的所有段落也可以在paragraph 层级单独设置——示例先用add --type paragraph铺好段落文本再set --prop list...统一套样式比逐段设置更紧凑且能精确控制哪几个段落变列表、哪个段落保持普通标题。四、Slide 3 — 样式化 Run富文本第三页演示单个段落内部按 run 粒度混合样式第一块是 The quick brown fox… 的经典字体样式演示第二块用baselinesuper/sub输出 Emc² 与 H₂O 的上下标第三块则是删除线 强调色的价格划线对比。officecli add textboxes-basic.pptx / --type slide # 空文本框 —— 通过 --type run 逐 run 填充 officecli add textboxes-basic.pptx /slide[3] --type textbox \ --prop x0.5in --prop y1.5in --prop width12in --prop height1in \ --prop text --prop size20 # 向段落 [1] 追加不同样式的 run officecli add textboxes-basic.pptx /slide[3]/shape[1]/p[1] --type run \ --prop textThe officecli add textboxes-basic.pptx /slide[3]/shape[1]/p[1] --type run \ --prop textquick --prop boldtrue --prop colorE63946 officecli add textboxes-basic.pptx /slide[3]/shape[1]/p[1] --type run \ --prop textbrown --prop italictrue --prop colorA0522D officecli add textboxes-basic.pptx /slide[3]/shape[1]/p[1] --type run \ --prop textfox jumps over the officecli add textboxes-basic.pptx /slide[3]/shape[1]/p[1] --type run \ --prop textlazy --prop underlinesingle --prop color2A9D8F officecli add textboxes-basic.pptx /slide[3]/shape[1]/p[1] --type run \ --prop textdog. # 上下标 —— 通过 baseline也接受 baselinesuper/sub officecli add textboxes-basic.pptx /slide[3] --type textbox \ --prop x0.5in --prop y3in --prop width12in --prop height0.8in \ --prop text --prop size24 officecli add textboxes-basic.pptx /slide[3]/shape[2]/p[1] --type run \ --prop textE mc officecli add textboxes-basic.pptx /slide[3]/shape[2]/p[1] --type run \ --prop text2 --prop baselinesuper officecli add textboxes-basic.pptx /slide[3]/shape[2]/p[1] --type run \ --prop text and H officecli add textboxes-basic.pptx /slide[3]/shape[2]/p[1] --type run \ --prop text2 --prop baselinesub officecli add textboxes-basic.pptx /slide[3]/shape[2]/p[1] --type run \ --prop textO # 同一段落内 删除线 字号覆盖 officecli add textboxes-basic.pptx /slide[3] --type textbox \ --prop x0.5in --prop y4.2in --prop width12in --prop height0.8in \ --prop text --prop size20 officecli add textboxes-basic.pptx /slide[3]/shape[3]/p[1] --type run \ --prop textOLD PRICE: \$99 --prop strikesingle --prop color999999 officecli add textboxes-basic.pptx /slide[3]/shape[3]/p[1] --type run \ --prop textNOW \$49! --prop boldtrue --prop colorE63946 --prop size24本页特性--type run向父p[N]段落追加 run、bold、italic、underlinesingle、double 等、strikesingle、double、colorhex、sizept、baselinesuper、sub 或带符号的整数百分比。run 的路径与扩展属性根据 run.json--type run在a:p内部追加a:r路径为/slide[N]/shape[M]/p[K]/r[L]别名r字体属性落在a:rPr上。文档中值得注意的扩展点baseline以字体高度的百分比表示垂直偏移接受super等价 30、sub等价 −25、none/false/0或带符号数字如--prop baseline-25readback 为带%后缀的百分比如30%、-25%。另有subscripttrue/superscripttrue两个布尔语法糖读取时统一规范化为baseline。按字符区间格式化set shape-or-paragraph-path --prop rangeSTART:END --prop boldtrue可将样式只应用到指定字符区间0 基、半开区间支持多段区间如range6:11,20:25find按文本定位与range按偏移定位在同一调用中互斥。更多 run 级属性highlight字符背景高亮任意颜色、kern字距调整起始字号1/100 pt、spacing/charspacing字符间距 pt负值收紧、capnone/small/all别名allCaps/smallCaps、textOutline[.width/.color]字形描边、langBCP-47 标签别名lang.latin但lang.ea/lang.cs在 DrawingML 中被拒绝——PPT 只有一个主语言槽与 Word 不同。命令转义提醒源自 officecli-pptx SKILL示例中价格文本写作\$99正是为了应对shell 层的展开双引号内的$99会被 bash 当作变量展开$9展开为空导致文本变为99。所以包含$的文本要么整体单引号--prop text$15M要么在双引号内写\$。另外 CLI 会解释\n段落/换行与\t制表符两字符转义若要输出字面\n需写成\\n。五、Slide 4 — 多语言字体 垂直对齐 内边距第四页处理多语言排版的三件套按脚本分槽选字体Latin 与 East Asian 分开、高文本框内的垂直对齐、以及正文内边距。officecli add textboxes-basic.pptx / --type slide # 混合脚本文本框font.latin 用于拉丁字符font.ea 用于东亚字符 officecli add textboxes-basic.pptx /slide[4] --type textbox \ --prop x0.5in --prop y1.5in --prop width6in --prop height2in \ --prop fillF1FAEE --prop margin0.2in \ --prop textHello, 世界! こんにちは、世界。 \ --prop size24 --prop boldtrue \ --prop font.latinGeorgia --prop font.eaYu Mincho # valign —— 高固定框内文本的垂直位置 # top (default), middle, bottom X7 for va in top middle bottom; do officecli add textboxes-basic.pptx /slide[4] --type textbox \ --prop x${X}in --prop y1.5in --prop width2in --prop height3in \ --prop fillA8DADC --prop margin0.15in \ --prop textvalign$va --prop size16 --prop boldtrue \ --prop valign$va --prop aligncenter X$(echo $X 2.2 | bc -l) done officecli close textboxes-basic.pptx officecli validate textboxes-basic.pptx本页特性font.latinLatin 脚本字体槽、font.eaEast Asian 脚本字体槽、valigntop、middle、bottom、margin统一内边距另有marginLeft、marginRight、marginTop、marginBottom、aligncenter。分脚本字体槽来自 textbox.jsonfont.latin仅写 Latin 脚本槽OOXMLa:latin如--prop font.latinCalibrifont.ea仅写 East Asian 槽a:ea覆盖中文/日文/韩文别名font.eastasia/font.eastasianfont.csComplex-script 槽a:cs覆盖阿拉伯文/希伯来文/泰文等裸font一次性同时设置 Latin 与 East Asian以及 cs槽适合拉丁为主的文本。run 层的font写入是写直达、读规范--prop fontCalibri会同时铺满 latin/ea/cs 三个槽读取时则规范化为font.latin/font.ea/font.cs三个键保证 get→set 往返不丢失槽位差异。这正是示例中混合脚本文本必须用font.latinGeorgia --prop font.eaYu Mincho的原因——同一行内 Hello, 走 Georgia世界 走 Yu Mincho。垂直对齐与内边距valign垂直锚定a:bodyPr/anchor取值top/center/middle/bottom其中middle是center的输入别名读取统一回读为center。在固定高度height3in的高框内它是把文字稳定压到顶部/居中/底部的唯一手段。margin正文四边内缩a:bodyPr的lIns/tIns/rIns/bIns。单值如margin0.2in同时作用于四边也支持 CSS 风格四值形式margin0.2cm,0.5cm,0.2cm,0.5cm0/0cm是合法值且会被保留不会坍缩为默认值。读取时若四边一致返回单个长度否则返回逗号分隔的四元组。单边微调则用marginLeft、marginRight、marginTop、marginBottom。六、完整功能覆盖表下表汇总四个演示页面与全部涉及的属性原文档的覆盖表附属性规范出处FeatureSlide规范出处align:left, center, right, justify1textbox.jsonfill:hex color background1–4textbox.json--type paragraph:append paragraph to existing shape2paragraph.jsonlistbullet:bulleted list at shape level2paragraph.jsonlistnumbered:numbered list at shape level2paragraph.jsonlevel:indent depth for sub-items (0top, 1nested, …)2paragraph.json--type run:append styled run to a paragraph3run.jsonbold / italic:per-run weight and style3run.jsonunderline:single, double, heavy, dotted, dash3run.jsonstrike:single, double3run.jsoncolor:per-run text color (hex)3run.jsonsize:per-run font size (pt)3run.jsonbaseline:super, sub, or signed integer % offset3run.jsonfont.latin / font.ea:per-script font slots4textbox.jsonvalign:top, middle, bottom4textbox.jsonmargin:uniform inner text padding4textbox.jsonaligncenter:horizontal center within valign demo4textbox.json七、检查生成结果query / get 逆向验证构建完成后使用query跨幻灯片搜索与get按路径读取单个元素验证各页状态。这既是回归检查也是熟悉元素路径层级的好机会——textbox → shape[N] → p[K] → r[L]的嵌套关系一目了然# 列出 slide 1 上的所有 shape officecli query textboxes-basic.pptx /slide[1]/shape # 读取每个文本框的对齐方式 officecli get textboxes-basic.pptx /slide[1]/shape[2] # 检查 slide 2 两个 shape 的列表类型 officecli get textboxes-basic.pptx /slide[2]/shape[1] officecli get textboxes-basic.pptx /slide[2]/shape[2] # 检查 slide 3 段落 [1] 的全部 run officecli query textboxes-basic.pptx /slide[3]/shape[1]/p[1]/run # 读取 slide 4 的 valign 与字体 officecli get textboxes-basic.pptx /slide[4]/shape[1] officecli get textboxes-basic.pptx /slide[4]/shape[3]get默认返回元素属性含effective.*继承解析值query支持shape:contains(...)、shape[fill1E2761]、shape[width10cm]等 CSS 风格选择器--json输出机器可读。注意路径中的[N]一律加引号包裹/slide[1]否则 zsh/bash 会把[1]当作 glob 展开导致no matches found。八、Python SDK 等价实现一次 batch 完成全流程Shell 版本逐条调用 CLItextboxes-basic.py 则演示了面向 Agent 的高效路径启动一个常驻进程resident把全部 slide/shape/paragraph/run 构建项打包进单个doc.batch(...)往返。每个 item 就是你会放进officecli batch列表的{command,parent,type,props}字典且按顺序应用——后一项可以寻址前一项刚创建的 shape例如 paragraph 立即指向同批中刚 add 的/slide[2]/shape[1]。import officecli # pip install officecli-sdk或使用仓库内 sdk/python/officecli.py with officecli.create(FILE, --force) as doc: items [] items.append({command: add, parent: /, type: slide, props: {}}) items.append({command: add, parent: /slide[1], type: textbox, props: {text: Horizontal Alignment, size: 28, bold: true, x: 0.5in, y: 0.3in, width: 12in, height: 0.6in}}) # ... 每个 add/set 都以同一字典形状累积 ... items.append({command: set, path: /slide[2]/shape[1], props: {list: bullet}}) doc.batch(items)Python SDK 的完整实现位于 sdk/python/officecli.py对应的 Node SDK 见 sdk/node/index.js 与类型声明 sdk/node/index.d.ts两个 SDK 都附带可独立运行的冒烟测试sdk/python/smoke.py、sdk/node/smoke.js。文本元素的分层结构shape→paragraph→run在 SDK 与 CLI 之间完全一致因此 Shell 教程中的任何属性都能原样移植到 batch 字典中。九、底层实现要点与常见陷阱OOXML 映射从源码与 schema 可以确认三个元素类型的底层对应textbox/shape→p:spPowerPoint shape正文在a:txBody位置/尺寸在a:spPr正文内边距与垂直锚定在a:bodyPr见 PowerPointHandler.Add.Shape.cs 的类型分派与 bodyPr 处理paragraph→a:p位于 TextBody 内段落属性在a:pPrlvl、marL/marR、buChar/buAutoNum等默认 run 样式在defRPrrun→a:r字符属性在a:rPrb、i、u、strike、sz、baseline、solidFill、latin/ea/cs字体槽等。PptxBatchEmitterPptxBatchEmitter.Shape.cs在导出时会把无几何预设的纯文本形状标记为textbox、带几何的标记为shape这正是add 时两者等价、dump/readback 时按形状类别区分的往返设计。高频陷阱清单陷阱正确做法zsh/bash 未加引号的[N]路径总是加引号/slide[1]zsh 会把未加引号的[1]glob 成no matches found--name foo直接传所有属性都走--prop--prop namefoo/shape[myname]裸名用name选择器/shape[namemyname]或/shape[id10007]路径 1 基 vs--index0 基/slide[1]是第 1 页--index 0才是第 0 个位置--prop text中的$单引号包整个值--prop text$15M双引号$15M会被 shell 展开成M\n/\t在--prop text中由 CLI 解释\n 段落换行、\t 制表符字面\n需写\\nsize/bold/color在 textbox 层读取不到读取用effective.size/effective.color/effective.bold或在 run 层读取valignmiddle读取不一致middle只是center的输入别名读取回center十、小结一个可复用的文本构建工作流把四页示例抽象为通用流程create → open → add slide → add textbox位置/尺寸/背景/初值→ add paragraph追加段落→ add run行内混合样式→ set列表/其他属性批量应用→ close → validate → query/get 复核。再叠加三点心法粒度分层整段一致的样式放 shape/paragraph 级行内混排放 run 级或range区间避免无谓拆分显式排版OfficeCLI 没有布局引擎x/y/width/height、valign、margin全部显式指定这也意味着可以精确复刻任何设计稿先 set 后验证结构操作后用get /slide[N] --depth 1确认 shape ID交付前用view issues检查溢出、validate检查 schema必要时用view html做视觉审计。如果需要在批处理场景循环网格、多页骨架复用这些模式officecli-pptx SKILL 中的batchheredoc 配方坐标数学内联进 JSON无需bc/bash 数组与 textboxes-basic.py 的单次doc.batch都是直接可抄的模板。更多元素chart、connector、animation、table、zoom的属性参考可随时通过officecli help pptx element查询本机安装版本的权威 schema。赞分享CLIAI 应用MCP 服务【免费下载链接】OfficeCLIOfficeCLI is the first and best Office suite purpose-built for AI agents to read, edit, and automate Word, Excel, and PowerPoint files. Free, open-source, single binary, no Office installation required.项目地址https://gitcode.com/GitHub_Trending/of/OfficeCLI点击查看免费下载相关推荐使用 OfficeCLI 创建 PPT 文本框对齐、列表、富文本与多语言字体的完整实战指南使用 OfficeCLI 创建 PPT 文本框对齐、列表、富文本与多语言字体的完整实战指南 导读 本文以 textboxes basic.md https:/人工智能AI 应用AI 技能CLIMCP 服务OfficeCLI 幻灯片表格边框完全指南从 border.all 速记到对角线分割的实战解析OfficeCLI 幻灯片表格边框完全指南从 border.all 速记到对角线分割的实战解析 导读 PPT 表格边框是演示文稿中最常见也最容易被忽略的细节人工智能AI 应用AI 技能CLIMCP 服务presenterm 幻灯片布局指南用 HTML 注释命令实现多列与居中排版presenterm 幻灯片布局指南用 HTML 注释命令实现多列与居中排版 本指南围绕 presenterm一款 Markdown 终端幻灯片工具内置的CLI上一篇Kubernetes CRD 完全指南使用 CustomResourceDefinition 扩展 Kubernetes API下一篇3步构建Proxmox VE专业监控系统Grafana仪表盘配置全攻略创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考