如何使用IronPPT與Claude Code

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

一間培訓公司為其C#課程的每次課程發佈PowerPoint講義。 每個模組都有一個大綱文件,列出主題、每個主題下的要點、代碼示例和偶爾的警告,而一個家樣式文件則固定每種文本的字體、大小和位置。 當手動組裝幻燈片時,一個錯誤的字體或一個重疊的文本框都可能未被發現,直到學員打印講義時。 Claude Code,Anthropic的軟體代理,在終端、VS Code、JetBrains、桌面應用程式及網路上運行。 在每個環境中,它會讀取倉庫,修改文件並執行命令。

IronPPT是一個.NET程式庫,無需Office Interop即可創建和編輯PowerPoint文件。AddText將文本添加到幻燈片,如添加文本指南所示,TextStyle則設置其字重、字體和大小。四個測試過的提示設置Claude Code並讓其構建講義生成器。 每個提示所依賴的IronPPT文本行為記錄在旁邊。

快速開始
NuGet使用NuGet安裝

PM > Install-Package IronPPT

在 NuGet 包管理器控制台中運行上述命令安裝 IronPPT,或在 NuGet 包管理器中搜索該包。

在專案資料夾中打開終端,運行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.
Text


Claude Code在.NET展示專案中做什麼?

代理編寫生成器,讀取大綱文件,為每個模組構建一個幻燈片,並將每個保存的幻燈片與樣式文件進行比較。當檢查失敗時,它會讀取生成的報告,修正生成器並再次運行。 開發者決定每張幻燈片的家樣式和文本。

首次提示會命名IronPPT套件及其版本。 如果代理被賦予選擇套件名稱的自由,可能會安裝一個攻擊者註冊的套件,名稱由AI工具生成但不存在真實套件使用。 這種攻擊被稱為slopsquatting。

您如何設置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.
Text

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.
Markdown

IronPPT自己通過一個名為IronPPT.LicenseKey的環境變量進行讀取,探測發現它忽略IRONPPT_LICENSE_KEY。

IronPPT在幻燈片上放置文本在哪裡?

Slide.AddText將文本寫入一個150x100點的新形狀中,但沒有位置。 添加文本指南的截圖顯示了第一張幻燈片上的結果,其中“Hello from IronPPT!”三行包裹在左上角的窄框中。 在相同幻燈片上的每個進一步的AddText調用寫入了另一個沒有位置的同大小形狀,形狀因此重疊。

講義需要每種文本都放在固定的位置。 TextBox接受Position、Width和Height,都以點數計算,而IronPPT把它們寫到幻燈片上作為偏移和範圍。 幻燈片本身是720x540點,標準的4:3大小,所以為寬屏幻燈片編寫的樣式文件不合適。

從測試運行中模組3講義的標題幻燈片顯示了三個標題框,每個框已從樣式文件中放置和調整大小。

從其幻燈片XML按比例繪製模組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.
Text

提示的兩部分使得講義準確無誤。

  1. 作為單一來源的樣式文件:每個字體、大小、字重、對齊方式和框全都來自一個文件中,這樣檢查器可以將每個段落與訓練者所寫下的值進行比較。
  2. 一個讀取XML的檢查器:在重新加載後,IronPPT報告每個字體大小、位置和盒子尺寸為幻燈片XML中值的12,700倍,每個對齊為左側。 基於IronPPT的讀取器所做的檢查會無法通過正確的幻燈片。
提示: 只有所有框都是放置的TextBox並且所有字體都通過LatinFont設置時才批准該計畫。

可以在沒有授權金鑰的情況下測試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.
Text

信任生成的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行,少於報告文件所持的行。
  • 代碼行具有四個前導空格和帶重音符的教練姓名在幻燈片中保持不變。
  • 這兩份講義都通過了Open XML SDK驗證器的檢查,未發現任何0錯誤。
  • 生成器創建了每個框作為定位的TextBox,並且從未調用了AddText。
  • 子代理未找到無位置的文本框,也沒有規則列表中失落的設置。
  • 在沒有IRONPPT_LICENSE_KEY的過程中悉儉件6失敗,並且在一個新的克隆中再次通過。
  • 在一個新克隆的Release運行中生成了相同的兩份講義和相同的38行。
  • 沒有金鑰情況下,程序跳過了兩個模組並寫了一個有標頭但沒有行的報告。
  • 本次運行中,沒有轉錄、會話文件或倉庫文件中出現授權金鑰。
  • 一些步驟與頁面上運行的不同。 會話無頭運行,因此計划顯示在回復中,並且一個鍵入的回復批准了它。 運行的守衛將代理保持在倉庫內,阻止了Claude Code嘗試在用戶資料中保存的計划文件。

在模組3講義中,幻燈片3保存了第二個主題,帶有它的兩個要點和三行代碼。

從其幻燈片XML按比例繪製模組3講義的幻燈片3。

在測試運行中IronPPT保存的模組3講義的幻燈片3。它按比例從幻燈片XML中在其字體和大小中繪製。框線來自於繪圖腳本,而不是PowerPoint渲染。

Cursor指南還讓代理先撰寫計畫,Cursor將其保存為可編輯的Markdown文件。ChatGPT Codex指南將其幻燈片規則保留在AGENTS.md中,Codex在任何工作前都會讀取這些規則,就像這個指南對CLAUDE.md所做的那樣。 此運行的Claude Code版本、模型、時間和測試機器在共享的運行記錄中。


疑難排解


問題?

如果您有任何疑問,請聯繫support@ironsoftware.com

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

閱讀更多

準備好開始了嗎?

NuGet 下載次數 7,110版本:2026.11剛剛發布