lark-cli 實戰 03:AI Agent 操作飛書幻燈片全流程實測(含 XML 模板)
发布于 2026-04-16 00:01:00(微信公众号导出记录)。
本文来自公众号后台的“导出文章内容”功能。博客正文由导出长图进行本地 OCR 转写,并保留原始排版图用于逐段核对。
原文链接:查看原文
OCR 转写有效文字约 6401 字;代码、流程图和版式以文末原始排版图为准。
正文(本地 OCR 转写)
XML模板) wex7ce EI V1ajero 2826年4月16日 86:81 日本 本文記祭了 AI Agent(Claude)通遇Lark-cl1 操作飛害幻燈片的完整實测程。幻 增片通透XML格式定差真面内容,支援文本、矩形、線保、表格、固表等元素。每一個命 令都在同服器上青际行退。 工具: Claude Code + lark-cl1 v1.9.9 核心思路和之前的文檔、表格一楼:Agent直接調用lark-cli命令,通過XML格式創疆 和管理幻燈片。不需要闹發飛書应用。
一、前置:補授權幻燈片權限
如果之前有授權通 slides 相盟 scope,操作蜜報missing_scopc。授權: lark-cli auth login --scope *slides:presentation:create slides:presenta 走DeviceFLow 授權後,實返回: 0K:登成功!侵用者:w9x7ce 本次新授予 scopes: slides:presentation:create slides:presentation:write 榴限表: 操作 所需 scope presentat1on:create 创建 PPT
- write_only
端取 PPT presentation:read presentation:update 添加/剩除真面 或write_only
二、幻燈片XML基
飛書幻澄片用XML定薪页面内容。理解XML结横是操作幻经片的前提。
2.1最小可用例
<slide xmlns=http://www. larkoffice.com/sml/2.0s
sstyles
cfills<fillcolor color=rgb(z48,258,252)/a</fill>
</style>
sdata>
=1461o4 -808.=41pin -88,=Afa7d01 08.x4f7d01 a1x91.=odk4 ade4ss
<content textType="title"s
<p>页面题/p
c/contenta
</shapes
c/data>
s/slides
2.2 slide 的結構
"slidex cstyles <!--面标式(背景色等) <fill><fillcolor color=.../>s/fill> </styles cdatas <!--页南元素容露-- <alxat,=adfg adeqss <!文本框 cshape type-'rect"> <!--短形/膜 ctables <!--表格 <chart> 置表 elines </ - 直综 <ing> <!--显片 ≤/data> enotex 济旗密储驻- </ - - <contentsp>内容/ps/content> ≤/note> </slides
2.3背景色和渐
色背景: sfill>sfillcalor color="rgb(248,25e,252)"/2s/fill> (+) sfill><fillcalar color=*linear-gradient(135deg,rgba(15,23,42,1) 8%, rgba 坑:浙色必须用rgba[)格式加百分比停靠點,用rgb或省略停靠粘售導 致背景整成白色。
2.4座標和尺寸
PPT壶布预段966x540。所有元素用topLcftx、topLeftY(左上角座标)、width、h elght 定位: (960,0) (0,0) topLeftx,topLeftY w1dth- |height (969,540) (0,540)
2.5文本檬式
scontent textType=*title" color=rgb(255,255,255) bold="true' textAlig p>檬题文本</p s/content> 常用性: 说明 隔性 值 textTy t1tle/headline/sub-headlin 文本频型,决定预設字 e/body/caption pe font51 手動設定字號(t1tle=54,headl1n 数字 ze e=38, body=16 ) rgb() 文字颜色 color 加粗 bold true/false textAl 封 left/center/right ign
三、創建空白PPT
三、
PPT lark-cli slides+create-title“我的演示文”
-
-a5 user
-
ok": trwe,
-
data":{
-
xnl_presentation_1d": *UE5rs5QBILPDUvdzDHxcAIeBnNh",
"title":“我的演示文稿",
"url": "https://d7fwkz4t4y.feishu.cn/slides/UE5rs50BIlPpuvdzDMxcAIel
'revision_id*: 1
創建的是一個空白PPT,没有任何真面。需要後婚用xnL_presentatlon.sLide create 页添加
四、一步創建带页面的PPT(推)
slidc5参数,在创建PPT的同时直接离入页面内容。10页以内推满此方式。 用 lark-cli slidcs crcate--title“lark-cli 如耀片功嵌全置--as uscr --slid
- sslide xmlns=http: //ww.larkoffice.com/snl/2.o>sstyle>sfill>sfil
實际返回:
-
ok": true。
-
data": {
"xml_presentation_id": TyizsQyunlmY2FdJbPEcN4Afn8g", "slide_ids: [*puu", pUa].
- 2:,pappe sa!1s-
"url": "https://07fwkz4t4y.feishu,cn/sl1des/Ty1zs0yumlmY2FdJbPEcN4.
"revision_id*: 1
關键返回值: xnl_presentation id-後所有操作的 ID
-
slide ids-每真幻澄片的 ID(按顺序)
-
slidesadded-實原添加了频页
五、添加新真面
向已有PPT追加新真面(超退10页時用这個方式逐真添加): Lark-cli slides xnl_presentation.slide create
-
a5 user \
-
-params 4"xnl_presentation_id':"TyizsQyunlnY2FdJbPEcN4Afnog}' \
3'aotjoyye //:dnu=sunux aptis>, yuaquoa bue-- u- b$ eiep-- cstyle><fill><fillcolor color=rgb(248,25a,252)/>s/fill></style> cdatax cshape type=text" topleftx="se" toplefty=4o width="aae" height= <content textType="headline" color="rgb(3o,6s,114)"> <P>常用XML元系</p </contents cadeys/s cshape type=text" topleftx-"80" topleftY-"130" width-"800" height <content textType="body' color="rgb(3a,41,59)> <a<strong>shape</strong> - 文本框(type=text)、矩形(type=rect]</f <p><strong=chart</strong> 表</p> </contents </shapes c/data> </slide>′{slide: (content:$content))*1"
-
cote": θ,
-
data":{
-
revision_1d*: 6,
und. :aP! ap!1s, ), 'nsg": "success*
技巧:用jq-n--arg content“XML'{slide:[content:$content}}可以避 免手動动XML中的引。比直接寫
- dataJSON方便得多,
六、讀取PPT全文内容
lark-cli slides xnl_presentations get
-
as user \
-
-params '{"xnl presentation id*:TyizsqyunlnY2FdlbPEcN4Afneg}"
返回完盈的XML内容,包含所有真面的群细瓷鼠。可以用来:
-
確真数是否正值
-
检查每页内容是否完整
-
取slide_id用岭後續删除操作
七、删除页面
lark-cli slides xnl_presentation.slide delete \
-
as user
-
-params ‘<"xnl_presentation id*:TyizsqyuntnY2FdJbPEcN4Afneg.*slide
實际返回: {cote": θ, “data: {“revision_id*: 7 }, “nsg*: *sucress" } 注意:删除操作不可逆。PPT至少保留一真幻澄片,不能刑除最後一真。
八、XML元素實戴例
8.1封面真模板(深色渐背景)
cslide xmlns= http: //www. larkoffice.com/sml/2.0*s sstyles <fill><fillcolor color-Linear-gradient(135deg,rgba115,23,42,1) e% s/styles cdatax <shape type=text" toplettx-"80" toplettY-150" width-"800 height <content textType="title color="rgh(25s,2ss,255)" textAlign="ce cd/>cd </contents </shape> 1461o4 -088=41p1a -08z,=4o7d01 -08.=x+fo7d0l s4xo4=odf4 ade4ss <content textType"body color="rgb(200,200,200)" textAlign-"cen <p>副想翘脱明</p c/contenta </shapes <shape type=*text" topleftx=*se" topleftY=44e- width=aae heiyht: ccontent textType="caption color="rgb(15e,15e,159)" textalign=" <p>wex7ce |2026-04-13</ps </content> code4s/s c/datas s/slides
8.2内容页模板(色背景+左侧暨線装飾)
cslide xmlns==http://www.larkoffice.com/sml/2.0*>
estyles
<fill><fillcolor color=′rgb(248,25e,252)*/s/f1ll>
</stylea
cdatax
<shape type=text" topleftx=ee" toplefty=4o width="aee height=
<content textType="headline" color="rgb(30,6s,114)">
<p>页面標箱</p
</contents
≤/shape>
<shape type=rect" topleftx="80" topleftY-"11o" width-"4′ height-"
<style>sfillssf11lcalor color="rgb(59,130,246)/></fill>s/style>
</shape>
<shape type-"text" topleftx-"10o" toplefty-12e" width-"78e" heigh"
<content textType="body color="rgb(3a,41,59)>
<>正文内容第一段</p
</contents
≤/shape>
c/datax
2/slides
8.3结尾页模板
sslide xmlns==http://www. larkaffice.com/ sml/2.8*>
estyloo
<fill><fillcolor color="linear-gradient(135deg.rgba[15,23,42,1) c
s/style>
<data>
<shape type="text" toplettx="s0" topLeftY=200" width="80o height:
<rontent textType="title* color="rgh(2ss,2ss,255)" textalign="ce
<p>Thank Youc/pox
</contents
≤/shape>
4b1o4 -0ez-41pim -02e.-a4fondol .0se.-x+fondo1 -1sa1,-adla ode4ss
<style><fill><f1llcolor color="rgb(59,130,246)*/></fillsc/style>
</shape>
c/datax
c/slides
8.4矩形色瑰(装饰元素)
sshape type="rect* topleftx=8e toplefty="12a* vidth="35a" height=18 cstyle> <f1ll><fillcolor color=rgb(219,234,254)/></f1ll> sborder hardercolor="rgb(59,138,246)" borderMidlh="1"/> c/style> <content textType-"body" color-rgb(3e,41.59) textAlign-'center> <p<strang>卡片棵题s/strong></p> cp卡片内客</p </contents </shapes
九、踩坑記錄
原因 解决方案 同题 auth login --scope missing_scope 没有授程slides 權限 捕授權 必须用rgba()+百分比 渐翼背景白色 用了rgb()或省略了停靠點 停靠點 4001000 invalid XMIL格式错(想合、性 检查XML語法,確保概髓 结麒等) 正硫围合 param 用jq bash中雙引號薇
- -arg技巧避免手
XML和JSON引號嵌套 地默 無法副除唯一幻痘片 PPT至少保留一真 先添加新真面再刑除要的 shape 的 w1dth/he1ght 不剪 增大尺寸 文字被截 元系重叠 整座标,拉阴間距 topLeftX/topLeftY 位置衡实
十、全部命令清單
命令 创建空白 PPT slides +create 創建PPT亚同时添加真面(≤10真推 日 slides +create --slides 两) 取 PPT 全文 XML xnl_presentations get 已润 xnl_presentation.slide crea 向已有PPT添加新真面 已润 te xml_presentation.slide dele 删除报定真面 已测 te 共5個命令全部實潮通通。 本文所有命令和输出均為真實執行结果。實测PPT地址: https ://d7fwkz4t4y feishu, cn/slides/TyiZsQyumlmY2FdJbPEcN4Afneg
lark-cli:目录三 <上一篇·lark-cli實02:AIAgent操作飛書電子表格全流程實測(22功能)
原始排版图

