使用 IronPPT 与 AI 编程助手

Curtis Chau
Curtis Chau
更新: 2026年10月19日

IronPPT 是 Iron Software 的 .NET PowerPoint 库。 它可以从 C# 代码创建、打开和编辑 PPTX 演示文稿,无需 Microsoft Office 或 Interop,一个包就涵盖了运行 .NET Standard 2.0 的每个平台。

季度回顾甲板、一组课程讲义或一个物业列表都依赖于同几种操作:添加幻灯片、在其上放置文字和图像、在文件发送前更改顺序。 没有 IronPPT 文档的助手无法列出现有的成员,而 IronPPT 自己的一个指南示例编译和运行成功,但保存后的甲板保持不变。

每位助手的设置过程都是一样的。 添加包,从环境中分配密钥,为助手提供 IronPPT 的机器可读文档,并在标记任务完成前读取每个保存的甲板。 这适用于添加幻灯片、添加文本、管理图像和管理幻灯片。

Claude Code AI编程助手标志ChatGPT Codex AI编程助手标志GitHub Copilot AI编码助手徽标Cursor AI代码编辑器徽标Google Antigravity AI编码代理徽标

我的 AI 助手不能自行处理 PowerPoint 吗?

没有演示库,.NET 代码可以通过 Open XML SDK 编写 PowerPoint 文件,逐个部分构建演示文稿,并通过关系链接各部分。

IronPPT 将该包结构封装在一个小型对象模型中,其主要类型是 PresentationDocument 和 Slide。

在第一个提示之前有三件事实适用。

  • 无效果的调用不引发错误: 只有在读取保存的文件时才显示缺失的更改,而 IronPPT 在从路径再次打开甲板时执行该读取。
  • 包和命名空间的名称统一: 两者都是 IronPPT。 攻击者在助手推荐的不存在包的名称下注册恶意包,这种做法称为slopsquatting,所以在提示中包括确切的名称。
  • 许可证是永久的: IronPPT 许可证是一种一次性购买,无需更新费用,而许可页面列出了每个级别允许的开发人员人数。

步骤 1:安装 IronPPT

引用包后,助手使用 IronPPT 提供的类型。

Install IronPPT 2026.10.1 from NuGet and restore the project.
Tell me the IronPPT version it references afterwards.
Text

从终端显式固定版本发布。

dotnet add package IronPPT --version 2026.10.1
SHELL

包中不包含任何本机二进制文件,唯一的依赖项是 IronSoftware.Common 和 IronSoftware.System.Drawing。


步骤 2:应用您的许可证密钥

没有密钥的情况下,程序可以在内存中构建甲板并打开现有文件,但对 Save 的每次调用都会以 IronSoftware.Exceptions.LicensingException 和消息 Production License Required 失败。 消息还提到了七天的免费开发使用,但在本文探针的首次尝试中保存失败。 输入错误的密钥会导致未识别的许可证密钥,并且该消息的其余部分会重复密钥。 一个短密钥以全新方式出现,而一个包含一个字符更改的全长密钥则以其最后32个字符出现。 记录异常消息的代码因此将密钥材料写入其日志。 下面提供了一个免费试用密钥。

从今天开始在您的项目中使用 IronPPT 免费试用。

第一步:
arrow pointer

在应用程序启动时一次性分配许可证密钥,然后进行任何 IronPPT 调用。 从环境变量中检索它,因此不会将其存储在存储库中。

IronPPT.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPPT_LICENSE_KEY");
C#

分配有效密钥后,IronPPT.License.IsLicensed 被设为 true,IronPPT.License.IsValidLicense 报告密钥字符串是否有效。 没有以上分配,IronPPT 会忽略 IRONPPT_LICENSE_KEY。 它确实阅读了名为 IronPPT.LicenseKey 和 IRONPPT_LICENSEKEY 的环境变量,完全没有代码。

请注意: IronPPT 许可证密钥 还解释了如何在 appsettings.json 中设置密钥。

步骤 3:将您的助手定向为 IronPPT 的 LLM 文档

  • llms.txt 包含其 15 页中的每页的一行条目。
  • llms-full.txt 提供了 16 个文档页的摘要在一个文件中。
  • llms-full-catalog.txt 通过包括博客文章扩展索引。
  • API 参考 列出了每个成员的签名。
  • 支持技能文件的工具可以使用 skill.md,其中涵盖了设置、许可、食谱和常见错误。
  • AI 产品说明书 概述了支持的平台和主要用例。

在每次会话开始时提供索引。

Open https://ironsoftware.com/ppt/csharp/llms.txt before you write more IronPPT code.
Keep to what its linked pages document.

The IronPPT object model works like this:
- PresentationDocument is the deck, and a new one already holds one blank slide.
- AddSlide appends a Slide.
- Slide.AddText, Slide.AddParagraph and Slide.AddImage fill a slide.
- Slide.Remove deletes a slide, and setting Slide.Show to false hides it.
- Save writes the .pptx file, and the constructor that takes a path opens one.

For a member those pages leave out, do this:
1. Search https://ironsoftware.com/ppt/csharp/object-reference/api/ for it.
2. Build once to prove it compiles.
3. If you still can't confirm it, say so instead of guessing.

After that, list the IronPPT calls in this project that the docs don't cover.
Text

允许回答“未记录”给助手一个不编造方法的选项。


步骤 4:将 IronPPT 上下文添加到您的项目

将 IronPPT 规则存储在项目指令文件中,以便每次新会话都能读取它们。 Claude Code 读取 CLAUDE.md,ChatGPT Codex 读取 AGENTS.md,GitHub Copilot 读取 .github/copilot-instructions.md,Cursor 在 .cursor/rules/或 AGENTS.md 中读取 .mdc 文件,Google Antigravity 读取 AGENTS.md 或 GEMINI.md。 单个文本块与所有人兼容,虽然 Cursor 规则文件也包括 MDC 前言。 从以下内容开始。

Every deck in this project is built with IronPPT, under these rules:
- `IronPPT` is both the NuGet package name and the namespace.
- Begin with the llms.txt index, https://ironsoftware.com/ppt/csharp/llms.txt.
- Tools that read skill files load https://ironsoftware.com/ppt/csharp/skill.md.
- Set `IronPPT.License.LicenseKey` from IRONPPT_LICENSE_KEY when the app starts.
- The program reads that variable itself and never lists environment variables.
- Keep the key out of output, logs, exception text, and source control.
- A wrong key's `LicensingException` message repeats the key. Log only its first line.
- A new `PresentationDocument` already has one slide. Use `Slides[0]` as the title slide.
- Add text, paragraphs, and images through `Slide` methods.
- Build slides in their final order, or set `Slide.Index` to move one.
- Edits to the `Slides` list do not change the deck.
- Remove a slide with `Slide.Remove()` and hide one with `Show = false`.
- On a deck opened from disk, replace a picture by removing it and adding the new image.
- Do not add the Open XML SDK or another presentation library.
- When IronPPT lacks a feature, report that rather than working around it.
Markdown

技能文件命名 IronPPT 2026.8.1 作为测试的发布,并且其单文件示例固定该发布。 它还将 Slides 描述为可以编辑以重新排序幻灯片的列表,并在 Save 需要密钥之前承诺七天的开发期。 2026.10.1 的探针与两个声明相矛盾。


步骤5:一次性设置提示

步骤 1 到 4 可以作为一条消息在项目或会议开始时发送。

Set this project up for PowerPoint work with IronPPT, following these rules:
- Reference the IronPPT package at version 2026.10.1.
- Assign IRONPPT_LICENSE_KEY to IronPPT.License.LicenseKey first thing at startup.
- The code reads that variable itself. Don't list environment variables.
- The key never shows up in the console, a log, or a committed file.
- Before coding, go through https://ironsoftware.com/ppt/csharp/llms.txt, then keep to it.
- Look up anything it doesn't cover at https://ironsoftware.com/ppt/csharp/object-reference/api/.
- Compile before relying on a member found there.
- Load https://ironsoftware.com/ppt/csharp/skill.md if the tool accepts skill files.
- When the skill file and the compiler disagree, believe the compiler.
- Put content on slides with Slide methods, not with PresentationDocument.AddText.
- Create the slides in their final order, since editing the Slides list changes nothing.

Save these rules to the instructions file your next sessions read.
Tell me which file you wrote and what else you changed.
Text

步骤6:产生可用代码的提示模式

指定幻灯片、它们的顺序和每个的内容。

模糊 使用 IronPPT 制作季度甲板。

更好 使用 Slides[0] 作为标题,然后按收入顺序每个地区添加一张幻灯片,每个都有一个粗体 32 点标题和三段,并保存 quarterly.pptx。

说明 IronPPT 发布版本和目标框架。 成员可以在发布间更改。

更好 在 .NET 9 上使用 IronPPT 2026.10.1,并在第一次 IronPPT 调用前从 IronPPT_LICENSE_KEY 分配密钥。

请求完整文件。 片段可以省略 using IronPPT.Models; 指令,它提供 Slide, Text 和 Image。

更好 返回整个 Program.cs,其使用指令和许可证行,准备就绪。


步骤7:验证收到的内容

以下每个错误都可以在 2026.10.1 中重现。

  • 添加标题幻灯片使用 AddSlide: 每个新 PresentationDocument 从一张幻灯片开始,基于标题布局构建。 添加自己的标题幻灯片的程序保存一个打开在空白幻灯片上的甲板。在 Slides[0] 上写标题,或先添加每个幻灯片,然后移除原始幻灯片,因为移除一个甲板的最后一张幻灯片会引发 InvalidOperationException。
  • 通过文档添加文本: PresentationDocument.AddText 将其文本附加到最后一张幻灯片的最后一段,而 PresentationDocument.AddTextBox 为文本框创建了新幻灯片。 通过 Slide 方法添加内容。
  • 用字符串参数风格化 AddText 的结果: 返回的文本没有样式对象,因此在其上设置属性会引发 NullReferenceException。 技能文件的风格化配方进行该调用。 分配一个新的 TextStyle。
  • 选择使用 FontFamily 的字体: 保存的运行没有携带字体。 LatinFont 将字体写入文件。

重新打开的甲板使用 IronPPT 正确返回其幻灯片计数和文字。 从 ppt/slides/slideN.xml 中的幻灯片 XML 读取位置、大小、对齐和颜色。 重新加载后,IronPPT 将居中文字报告为左,探针将十六进制颜色 #C00000 和 #FFC000 读取回来为 #00000000。位置、大小和字体大小在 文本和图像输出 下描述的 EMU 比例上。

让代理验证其自己的工作

助手可以自己运行这些检查并显示结果。

Do a clean Release build and run the app once more.

Then show me the evidence:
- The IronPPT types and members the code calls, each with its documentation page.
- The value of IronPPT.License.IsLicensed.
- Each saved deck's slide count and every slide's first line of text, read back from the file.
- Any hidden slide.
- Every shape's a:off, a:ext, algn and solidFill values, taken from ppt/slides/slideN.xml.
- Any image or text whose position, size, alignment or color differs from what the code set.

Read those four properties from the XML, never from a deck reopened with IronPPT.
End by saying whether each deck matches what the code meant to build.
Text

使用 IronPPT 编辑幻灯片

幻灯片顺序、删除和图像替换的行为与管理幻灯片指南和管理图像指南展示的不同。 本文的探针保存每个更改并回读 PPTX 部分。

  • PresentationDocument.Slides 每次调用返回一个新的列表。 Remove、Insert、RemoveAt 和该列表上的 Add 未更改保存的甲板中的任何内容,因此指南的重新排序示例保持原有顺序。
  • Slide.Remove() 删除了幻灯片,无论是内存中还是从文件加载甲板后。
  • 将 Show 设置为 false 将幻灯片保留在文件中并将其标记为隐藏。
  • Slide.Clone() 抛出了 MissingMethodException,因此不能复制幻灯片。
  • 使用 AddSlide 添加一个移除的幻灯片返回一个空白幻灯片。
  • 将 Slide.Index 设置移动了幻灯片,无论是在一个新甲板还是从磁盘打开的一个中,保存的文件保留了新顺序。
  • Slide.Images 持有 IImage 的值,因此指南的 Images[0].Replace(image) 调用绑定到通用元素 Replace 方法。 该调用替换了内存中构建的甲板中的图片,而从磁盘打开的甲板中的旧图片留下。
  • 将图片强制转换为 Image 到达 Image.Replace,它在重新打开甲板中工作,在内存中的甲板中抛出了 NullReferenceException。
  • 用 AddImage 删除图片并添加新图像在两种情况下都有效,虽然保存的包保留了旧图像作为未使用的媒体部分。

使用 IronPPT 文本和图像输出

保存的幻灯片 XML 和 Open XML SDK 3.5.1 验证器给出了以下结果。

  • 每个 Slide.AddText 调用创建了它自己 150 x 100 点的文本形状并未设置任何位置,因此形状继承其位置于幻灯片布局。
  • AddParagraph 将其段落添加到幻灯片的最后一个文本形状。
  • 一个新甲板的第一张幻灯片在 AddText 添加的文本旁边保留了空的标题和副标题占位符。
  • 图像 Position、Width 以及 Height 是以点计算的。 没有分辨率设置的 400 x 200 像素的 PNG,在不设置大小的情况下添加,变为 300 x 150 点,其像素大小在 96 DPI。
  • 在重新打开的甲板中,相同属性返回存储的 EMU 数字作为点,是设定值的 12,700 倍。
  • FontSize 设置 Point 为 32 写入 32 点大小,并 IsBold 写入粗体。
  • 通过 TextStyle.Color 着色的每个运行未通过验证,显示无效子元素错误,名称和十六进制颜色一样。没有彩色文本的甲板没有错误地验证通过。

一个您可以重复的结果

测试包括一个提示,您不必编写其中的任何代码。 在一个空文件夹中打开一个新会话,粘贴提示,并将结果与通过标准对比。

请注意: 测试需要 .NET 9 SDK、网络连接、可以运行终端命令的助手,以及在 IRONPPT_LICENSE_KEY 中的 IronPPT 试用或生产密钥。

提示

Create a .NET 9 console app that builds a quarterly regional deck with IronPPT.
If this directory isn't empty, tell me and stop.
Don't ask questions. Note your choice for each missing detail.
Keep every deliverable in this directory.

Work in this order:
1. Add IronPPT 2026.10.1 from NuGet.
2. Study https://ironsoftware.com/ppt/csharp/llms.txt, its license key page and four how-to guides.
3. Follow these code rules:
- Use only members those pages or the API reference document.
- At startup, the program itself assigns IRONPPT_LICENSE_KEY to IronPPT.License.LicenseKey.
- Never print the key, save it, or list environment variables.
- Stop with a message if IronPPT.License.IsLicensed is false.
- Print only the first line of a licensing error from Save.
4. Before building slides, the code writes qbr-data.json in thousands of dollars:
- Revenue/target: North 1240/1100, South 860/950, East 1410/1300, West 720/900.
- Three commentary lines of your own per region, under 60 characters each.
5. Draw each region's revenue and target as an 800 by 400 pixel PNG bar chart:
- Save charts/<region>.png and a grey background copy, charts/<region>-board.png.
- Encode the PNGs yourself, with no package or imaging library.
6. Build qbr.pptx with these seven slides in order, none blank:
- Title: "Quarterly Business Review" in bold 40 point, "Q3 2026" in 24 point.
- A slide headed "Agenda" listing the four regions.
- One slide per region, highest revenue first.
- A last slide headed "Next steps" with a "South: 90K below target" line per region below target.

Each region slide has:
- Its name as a bold 32 point heading, then one paragraph per commentary line.
- "Revenue 1410K against a target of 1300K" with its figures.
- That line in Color.Green if the target is met, otherwise Color.Red.
- Its chart at x 360, y 140, 320 by 160, all in points.
7. Reopen qbr.pptx from disk and save a board version, qbr-board.pptx, like this:
- Drop the agenda slide.
- Hide "Next steps" without removing it.
- Move the region with the largest shortfall right after the title.
- Swap that region's chart for its -board.png.
- Keep the rest in original order.
- Work around and note any change the save loses.
- As a last resort, rebuild from your data in the new order.
8. Build and run in Release.

The app fills readback.md only from both saved decks, reopened with IronPPT:
- A table per deck of each slide's position, first text line, visibility and image count.
- A section on each step where the guides' approach didn't work.

Its checks give expected, actual and match for both decks:
- Slide count and region order.
- Revenue line color, chart position and size per region slide.
- The board deck's moved region chart against its -board.png, by image bytes.
9. Fix each failed check and rerun, or describe an IronPPT cause nothing gets around and move on.
10. Report the Release build result, checks matched out of total, and your assumptions.
Text

输出

应用程序未编辑的 readback.md 列出了其幻灯片表和检查,两套甲板可在应用程序保存它们时使用,qbr.pptx 和 qbr-board.pptx。 下面的数字来自对保存的 PPTX 部分的独立阅读。

西部地区收入与目标的柱状图,由生成的应用程序绘制

西部图表的灰色板版本,应用程序用其自己的 PNG 编码器绘制并将其放置在 qbr-board.pptx 中,未编辑。

  • 适用于 net9.0 的发布版本完成,没有警告和错误。
  • qbr.pptx 以请求的顺序包含七张幻灯片,其中没有一个是空白的。
  • 应用程序通过在称为 Remove 的调用后移除已启动的新甲板的幻灯片,指南的列表调用没有效果。
  • 每个区域标题都为 32 点粗体。
  • 北部和东部的收入线为绿色,南部和西部的为红色。
  • 两个甲板中的所有八个地区幻灯片都在 x 360 和 y 140 点放置了图表,大小为 320 x 160 点。
  • qbr-board.pptx 包含六张幻灯片,其中西部地区低于目标 180K 的幻灯片直接位于标题之后。
  • 只有确定步骤幻灯片在董事会甲板中被隐藏。
  • 应用程序从磁盘打开的 qbr.pptx 构建了董事会甲板,并通过设置其幻灯片的索引属性移动了西部。
  • 董事会甲板中的西部幻灯片携带着应用程序编写的图表 PNG 的确切字节。
  • 应用程序的回读匹配了 22 次中的 22 次检查。
  • 独立读匹配其 60 次检查中的所有。
  • Open XML SDK 验证器在每个甲板中报告了六个错误,每一个有颜色的运行都报告了一个错误。
  • 项目文件夹中、其 Git 历史或 Claude Code 会话文件中没有包含许可证密钥的文件。
  • 设置提示将其十一条规则写入新 CLAUDE.md,并安装 skill.md 作为项目技能。
  • 有些步骤与页面中的运行不一样。 在同一会话中接受提示后,步骤 1、3、5 和 7 的提示运行。

通过的标准

  • 释放构建完成,无需手动编辑。
  • qbr.pptx 在步骤 6 设置的顺序中有七张幻灯片,没有一个空白,当您自己阅读文件时。
  • 每个地区幻灯片都持有其标题、三段评论、收入线和一个在请求位置和大小的图表。
  • qbr-board.pptx 有六张幻灯片,其中目标最多错过的地区就在标题之后,确定步骤幻灯片被隐藏。
  • readback.md 从保存的甲板中获取每个实际值,并命名每一个需要不同方法的步骤。
  • 搜索项目文件夹找不到包含许可证密钥的文件。
请注意: 要测试不同的发布版本,请编辑步骤 1 中的版本并查看IronPPT 变更日志中的更改。

运行记录

  • 所有运行都使用一台 Windows 11 x64 台式机,搭载 Core i9-14900KF 和 64 GB 内存。
  • 本指南的项目目标为 net9.0,并固定 IronPPT 2026.10.1。
  • 指南的持续时间是其页面上提示的日志时间总和,并且此指南的行数仅计算接受提示的。
  • 最后测试 2026 年 10 月 16 日,表格中的每个指南。
指南助手和版本模型持续时间(分钟)
本指南Claude Code 2.1.277,一个会话,关闭权限提示Claude Opus 518.2
Claude CodeClaude Code 2.1.277,计划模式下的提示3与 Opus 5 计划的第 5个奏鸣曲33.3
ChatGPT CodexCodex CLI 0.160.0GPT-6 Luna22.2
GitHub CopilotCopilot CLI 1.0.98,计划模式下的第 3 提示,问题主体和评论在自己的会话中GPT-6 Luna,Auto 选择16.1
CursorCursor CLI 2026.10.14,无头模式,计划模式下的第 3 提示,保持为提示 5 到 7 打开Composer 2.515.4
Google AntigravityAntigravity CLI 1.4.0,跳过权限提示Gemini 4 Argon (Medium)47.4

代理特定指南

下列每个指南将这些步骤应用于一个工具和一个演示任务。


故障排除


有问题吗?

如果您有任何问题,请联系support@ironsoftware.com

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

阅读更多

准备开始了吗?

NuGet 下载量 7,110版本:2026.11刚刚发布