如何使用IronPPT与Claude Code
一家培训公司为其每节C#课程发放PowerPoint讲义。 每个模块都有一个概述文件,其中包括主题、每个主题下的要点、代码示例和偶尔的警告,还有一个房屋风格文件固定每种文本的字体、大小和位置。 当幻灯片手动组装时,一个错误的字体或一个重叠的文本框可能不会被注意到,直到学员打印讲义。 Claude Code是Anthropic的软件代理,在终端、VS Code、JetBrains、桌面应用程序和网络上运行。 在每个环境中,它读取库,修改文件并执行命令。
IronPPT是一个.NET库,可以创建和编辑PowerPoint文件而无需Office Interop。AddText向幻灯片添加文本,正如添加文本指南所示,TextStyle设置其权重、字体和大小。四个经过测试的提示设置Claude Code并让它构建讲义生成器。 每个提示依赖的IronPPT文本行为记录在它们旁边。
在项目文件夹中打开终端,运行claude,在第一个提示之前输入/model opusplan。 以@开头的路径将该文件附加到请求中。
Install IronPPT from NuGet, version 2026.10.1, in TrainingHandouts.csproj.
Then turn Program.cs into a smoke test built from @course/module-03-async.json.
Program.cs runs these steps in order:
1. Applies the key, then prints the value of License.IsLicensed.
2. Adds the module's title value to the first slide with Slide.AddText.
3. Saves the deck as out/smoke.pptx, creating out/ if it's missing.
4. Loads out/smoke.pptx again and prints how many slides it has.
5. Lists every text box on each slide, with its text in quotes.
The key is in the IRONPPT_LICENSE_KEY environment variable, and these rules cover it:
- Program.cs reads the variable at startup and copies the value into License.LicenseKey.
- Never log the key, print it, or write it to a file.
- Don't run any command that lists environment variables.
- If you need to check the variable, tell me only whether it's set.
Run the program once and tell me what it printed.
最小工作流程(5 个步骤)
- 从 NuGet 下载 C# PowerPoint 库
- 从项目文件夹打开Claude Code并使用/model设置模型
- 在CLAUDE.md中记录IronPPT的测量文本规则,以便每个会话都加载它们
- 请求一个生成器,使每个文本框定位并从房屋风格文件中获取每种风格
- 在讲义打印前检查保存的幻灯片XML和风格文件
在.NET演示项目中,Claude Code做什么?
代理编写生成器,读取概述文件,每个模块构建一个幻灯片,并将每个保存的幻灯片与风格文件进行比较。当检查失败时,它会读取其生成的报告,纠正生成器并重新运行它。 开发人员决定房屋风格和每张幻灯片的文本。
第一个提示命名IronPPT包及其版本。 让代理选择包名称可能会安装由攻击者注册的包,攻击者使用AI工具生成的名称,但没有实际包使用。 这种攻击被称为失误入侵。
如何设置Claude Code?
按照Anthropic的快速入门安装Claude Code并登录。 当claude在终端中启动并响应时,设置完成。
如何设置一个Claude Code可以工作的项目吗?
在第一个提示前给代理真实输入。 .NET 9控制台应用程序的测试装置有一个课程文件夹,其中包含两个模块概述和房屋风格文件。模块3概述涵盖四个主题中的async和await,模块4概述覆盖三个主题中的LINQ。 风格文件定义了七个文本角色,每个都有字体、大小、权重、对齐和一个以点计的框。
CLAUDE.md在每个会话开始时加载,因此在那里写的规则适用于每个后续提示。 第二个提示创建文件和一个生成器代码的只读审阅者。
Write a CLAUDE.md for this repo.
Its Presentations section holds these rules for every later session:
- IronPPT is the only presentation library. Don't add the Open XML SDK or any other.
- Keep the IronPPT version that TrainingHandouts.csproj references now.
- Look up IronPPT member names in docs/IronPPT.xml before you use them.
- course/ holds the inputs. Leave every file in it as it is.
- Program.cs saves decks to out/, and each saved deck is opened again and checked.
Copy IronPPT.xml into docs/ now, from the ironppt 2026.10.1 package in the local NuGet cache.
It's under lib/netstandard2.0. If it's missing, tell me and keep going.
Next, add a subagent at .claude/agents/handout-layout-reviewer.md.
Its tools are Read, Grep and Glob, and no others.
It reviews Handouts/ and answers four questions:
- Which IronPPT types and members does the code use?
- Which of those are missing from docs/IronPPT.xml?
- Which text boxes reach a slide without a Position, Width and Height?
- Which style settings in the code does CLAUDE.md list as lost on save?
I'll add IronPPT's measured text rules to CLAUDE.md myself before the first review.
When you're done, tell me whether the XML copy worked.
Claude Code检测到新的副代理文件无需重启,只要会话启动时.claude/agents文件夹存在。 会话开始前在库中创建该文件夹。 有关成员列表之外的指南,IronPPT在llms.txt中列出其代理的文档。
哪些IronPPT文本规则属于CLAUDE.md?
每行都来自带有和不带许可证密钥的探测运行,每个保存的幻灯片从其幻灯片XML中读取回。 在演示文稿部分下粘贴块。
These text rules were measured on IronPPT 2026.10.1:
- IronPPT doesn't read IRONPPT_LICENSE_KEY. Assign License.LicenseKey before the first save.
- Without a key, decks build and load, but Save throws LicensingException and writes no file.
- LicensingException isn't public, so catch (LicensingException) fails with CS0122.
- Match that exception by its type name instead.
- new PresentationDocument() already has one slide, holding an empty title and subtitle.
- A slide is 720 by 540 points.
- Slide.AddText writes a 150 by 100 point box with no position. Two calls overlap.
- Give every TextBox a Position, Width and Height. All three are in points.
- Set the typeface with Font.LatinFont. Font.FontFamily is never written to the file.
- Font.FontSize is in points.
- Align with Paragraph.Style = new ParagraphStyle { Alignment = TextAlignmentTypeValues.Center }.
- Paragraph.Alignment and Paragraph.SetAlignment write left alignment, even for Center or Right.
- Leave TextStyle.Color unset. Each colored run fails Open XML validation.
- new Color(r, g, b) makes Save throw NullReferenceException.
- An Underline writes no u attribute, so nothing is underlined.
- A line break inside one AddText string stays inside one run. Use a Paragraph per line.
- After a reload, font sizes, positions and box sizes read back at 12700 times the XML value.
- It also reports every alignment as Left after a reload.
- So check fonts, sizes, positions and alignment in the slide XML, not through IronPPT's reader.
IronPPT自行读取名为IronPPT.LicenseKey的环境变量,探测发现它忽略IRONPPT_LICENSE_KEY。
IronPPT在哪里放置幻灯片上的文本?
Slide.AddText将文本写入一个大小为150 x 100点且无位置的新形状中。 添加文本指南自己的截图展示了第一张幻灯片上的结果,其中“Hello from IronPPT!”在左上角的窄框中跨三行。 同一幻灯片上每次进一步的AddText调用写入无位置的相同尺寸另一个形状,因此形状重叠。
讲义需要每种文本都在固定位置。 一个TextBox接受一个Position、一个Width和一个Height,全部使用点,IronPPT将它们写入幻灯片作为偏移和范围。 幻灯片本身为720 x 540点,标准4比3尺寸,因此为宽屏幻灯片书写的风格文件不适合。
测试运行的模块3讲义的标题幻灯片展示三个标题框,每个都根据风格文件放置和调整大小。

IronPPT在测试运行中保存的模块3讲义的幻灯片1。它按幻灯片XML中标明的字体和尺寸比例绘制。框轮廓来自绘图脚本,而不是PowerPoint渲染。
IronPPT写的每个文本框都是一个正文占位符。 幻灯片母版的正文风格,正文占位符所遵循,定义了一个项目符号字符和32点默认大小。
IronPPT向文件写入的文本风格有哪些?
IronPPT向文件写入加粗、斜体和设置的字体大小。 探测将Font.FontFamily设置为Consolas,未在运行属性中找到字体,而Font.LatinFont则写入字体。
对齐取决于哪个成员设置它。 Paragraph.Alignment和Paragraph.SetAlignment都将一个居中段落对齐至左。 将Paragraph.Style设置为含有TextAlignmentTypeValues.Center的ParagraphStyle写入居中对齐。 TextAlignmentTypeValues枚举在全球命名空间中声明,位于IronPPT.Enums之外。
每个有色运行,无论具名还是十六进制,均未通过Open XML SDK验证,因为IronPPT在颜色旁写入alpha和通道值而不是颜色内部。 Color(r, g, b)构造函数使Save抛出NullReferenceException。 一个Underline写入但没有打开下划线的线属性。 IronPPT本身的skill.md在其示例中使用SetAlignment、一个彩色的TextStyle和一个下划线,因此复制这些示例的代理获得相同结果。
您如何提示IronPPT代码编译?
在一个提示中请求生成器及其检查,并允许计划模式在任意文件更改前完成设计。 在发送提示前通过Shift+Tab切换至计划模式。 选定opusplan时,Opus编写计划,Sonnet在计划批准后实施。
Build Handouts/HandoutBuilder.cs and its checker, Handouts/HandoutChecker.cs.
Have Program.cs run both.
Every JSON file in course/ except handout-style.json is a module.
HandoutBuilder follows these rules:
- Each module becomes out/<id>-handout.pptx.
- Another method builds a deck without saving it.
- Each box takes font, size, weight, alignment and box from the style role of the same name.
- Slide 1 is the document's own first slide, with course, title and trainer boxes.
- Each topic then gets a slide, in module file order.
- The title box reads "Module <module>: <title>".
- The trainer box reads "<trainer>, <date>", with the date unchanged.
Topic slides get these boxes:
- heading, the topic heading.
- point, one paragraph per point.
- code, if any, one paragraph per line, leading spaces kept.
- warning, if any.
HandoutChecker reads each saved deck's slide XML from the zip:
- It writes out/handout-check.csv, one row per paragraph, and skips empty shapes.
- It infers roles from the module file and box order.
- One method checks one deck file and returns its rows.
- Its columns are Module, Slide, Role, Text, Typeface, SizePt, Bold, Italic and Align.
- Then come X, Y, Width, Height and Match.
- Align is left, center or right. No algn attribute means left.
- Match is yes when text matches the module file and the rest matches the style file.
Run the program and tell me how many rows say no per module.
Then show me what the handout-layout-reviewer subagent finds.
提示的两个部分保持讲义正确。
- 风格文件作为单一来源: 每个字体、大小、权重、对齐和框都来自一个文件,检查器可以将每个段落与培训人员记录的值进行比较。
- 读取XML的检查器:重新加载后,IronPPT报告每个字体大小、位置和框大小的值为幻灯片XML中的12,700倍,每个对齐为左。 构建在IronPPT读者上的检查会失败正确的幻灯片。
可以不用许可证密钥测试IronPPT讲义代码吗?
在内存中构建密件和加载已保存的密件都无需密钥。 只有保存需要一个,因此测试项目可以在无键的构建代理上检查幻灯片结构和检查器。
Add an xUnit project, TrainingHandouts.Tests, for net9.0 in a folder of its own.
Keep that folder out of the TrainingHandouts.csproj build, and don't add a solution file.
Copy course/ and out/module-03-handout.pptx into the test output folder as test data.
The tests cover these cases:
- HandoutBuilder makes 5 slides for module-03 and 4 for module-04, with no save.
- The second code line on the last module-04 slide keeps its 4 leading spaces.
- Saving any deck with no key applied throws an exception whose type name is LicensingException.
- That failed save leaves no file at the target path.
- HandoutChecker finds 0 rows marked no in the copied deck.
- A changed heading typeface in a copy of that deck's slide XML gives exactly 1 row marked no.
Run dotnet test on TrainingHandouts.Tests once.
Use a child process with IRONPPT_LICENSE_KEY removed.
Tell me how many tests passed.
在信任生成的IronPPT代码前,您应该验证什么?
在审阅中加入以下检查。
- 构建:
dotnet build拒绝不存在的成员。已发货的IronPPT.xml还记录编译且在保存中丢失其值的成员,因此成功构建仅证明名称存在。 - 幻灯片XML:比较每个段落的字体、大小、对齐和框与风格文件。
- 一份打印的讲义:课程开始前,打印一份幻灯片并确认没有文本框重叠。
有关具有固定通过标准且可重运行的完整IronPPT任务,请参阅AI编码助手指南。
在实际运行中这些提示生成了什么?
Claude Code在一个会话中按顺序运行四个提示。 规则块在提示3前进入CLAUDE.md。没有手动编辑代码。
- 在运行前,库中有课程文件夹和一行Program.cs,无包引用。
- 快速入门幻灯片中有1张幻灯片和三个文本框,其中两个为空的标题和副标题占位符。
- CLAUDE.md收到了五个项目规则,副代理文件仅列出Read、Grep和Glob工具。
- 提示3后,模块3讲义有5张幻灯片,模块4讲义有4张。
- 所有26个文本框都有风格文件提供的位置和大小。
- 在我们对幻灯片XML的检查中,所有38个段落在字体、大小、权重和对齐上匹配风格文件。
- 检查器的报告包含38行,没有行标记为否。
- Claude Code自己对提示3的总结给出37行,比报告文件少一行。
- 含有四个前导空格的代码行和带重音的培训人员名字在幻灯片上未变。
- 两份讲义以0错误通过Open XML SDK验证器。
- 生成器创建每个框为定位的TextBox且从未调用AddText。
- 副代理未找到无位置的文本框及未丢失规则列出的设置。
- 在无IRONPPT_LICENSE_KEY的过程中通过了6个测试中的6个,并在新的克隆中再次通过。
- 在一个新的克隆中进行的发布运行产生了相同的两个讲义和相同的38行。
- 没有密钥,程序跳过了两个模块,并写了一份带有标题及无行的报告。
- 在此次运行中,许可证密钥未出现在任何记录、会话文件或库文件中。
- 有些步骤与页面中的运行不一样。 会话无头运行,因此计划在回复中出现,一个键入的回复批准了它。 运行的保护器将代理留在库内,阻止Claude Code尝试保存在用户配置文件中的计划文件。
在模块3讲义中,幻灯片3持有第二个主题,包含其两个要点和三行代码。

IronPPT在测试运行中保存的模块3讲义的幻灯片3。它按幻灯片XML中标明的字体和尺寸比例绘制。框轮廓来自绘图脚本,而不是PowerPoint渲染。
Cursor指南也让代理先写一个计划,Cursor将其保存为可编辑的Markdown文件。ChatGPT Codex指南将其幻灯片规则保存在AGENTS.md中,Codex在任意工作前读取它们,正如此指南对CLAUDE.md所做的那样。 Claude Code版本、模型、时机和此次运行的测试机器在共享运行记录中。
故障排除
- 若
Save抛出LicensingException,应用许可证密钥 - 做工程支持请求以报告已保存文件中缺少的文本风格
有问题吗?
如果您有任何问题,请联系support@ironsoftware.com
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。