使用IronPPT與AI程式編寫助手
IronPPT是Iron Software針對.NET的PowerPoint程式庫。 它可以從C#程式碼中創建、打開和編輯PPTX簡報,而不需要Microsoft Office或Interop,單一套件就能涵蓋所有支援.NET Standard 2.0的平台。
季報審核簡報、課程講義或不動產清單都依賴於同樣的幾個操作,這些操作包括添加幻燈片、在其上放置文本和圖像,以及在發送檔案之前更改順序。 沒有IronPPT的文件,助手就沒有現有成員的清單,而IronPPT自帶的指導範例會編譯和運行,但會保存無變化的簡報。
每個助手的設置過程都是一樣的。 添加套件,從環境中分配密鑰,提供IronPPT的機器可讀文件給助手,並在標記任務完成之前讀取每個已保存的簡報。 這適用於添加幻燈片、添加文字、管理圖像和管理幻燈片。
如何使用AI程式編寫助手與IronPPT
- 從NuGet下載C# PowerPoint程式庫
- 在啟動時從
IronPPT_LICENSE_KEY分配IronPPT.License.LicenseKey - 在助手寫程式碼之前,給予助手IronPPT的llms.txt索引
- 在助手載入的說明檔中記錄IronPPT的規則
- 使用新簡報已經有的幻燈片,然後按照最終順序新增其他的
- 檢查每個已保存的簡報的幻燈片XML是否符合要求
我的AI助手不能單獨處理PowerPoint嗎?
沒有簡報程式庫,.NET程式碼可以透過Open XML SDK寫PowerPoint文件,這個SDK構建簡報時一部分一部分地搭建,並通過關係鏈接各部分。
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.
從終端,顯式固定版本。
dotnet add package IronPPT --version 2026.10.1
此套件不包含本機二進位文件,其唯一的依賴項是IronSoftware.Common和IronSoftware.System.Drawing。
步驟 2:套用您的許可證金鑰
沒有密鑰,程式可以在記憶體中構建簡報並打開現有文件,但每次調用Save時都會因IronSoftware.Exceptions.LicensingException失敗,並顯示消息需要生產許可證。 該消息還提到了七天的免費開發使用期,但在本文的探測中第一次嘗試保存失敗。 輸入錯誤的密鑰會導致無法識別的許可證密鑰,並且該消息的其餘部分會重複該密鑰。 短密鑰出現為完整形態,而更改了一個字符的完整版密鑰則顯示為其最終的32個字符。 記錄異常消息的程式碼因此將密鑰內容寫入其日誌。 下面提供了一個免費試用密鑰。
立即在您的項目中開始使用 IronPPT,免費試用。
在應用程序啟動時分配許可證密鑰,一定要在任何IronPPT調用之前。 從環境變數中檢索它,這樣它就不會存儲在存儲庫中。
IronPPT.License.LicenseKey = Environment.GetEnvironmentVariable("IRONPPT_LICENSE_KEY");
在分配有效密鑰後,IronPPT.License.IsLicensed設置為真正值,且IronPPT.License.IsValidLicense報告密鑰字符串是否有效。 如果沒有以上的分配,IronPPT會忽略IRONPPT_LICENSE_KEY。 它會讀取命名為IronPPT.LicenseKey和IRONPPT_LICENSEKEY的環境變數,無需任何程式碼。
步驟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.
回答“未記錄”的許可權給助理提供了一種除發明方法外的選擇。
步驟4:將IronPPT內容加入您的專案
將IronPPT規則存儲在專案指令檔,以便每個新會話可以讀取它們。 Claude Code讀取CLAUDE.md,ChatGPT Codex讀取AGENTS.md,GitHub Copilot讀取.github/copilot-instructions.md,Cursor讀取游標/規則/下的.mdc文件或AGENTS.md,Google Antigravity讀取AGENTS.md或GEMINI.md。 單一文本塊與所有相容,雖然游標規則文件還包括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.
技能文件將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.
步驟 6:產生可運行程式碼的提示模式
指定幻燈片及其順序和內容。
不明確 用IronPPT製作季度簡報。
較佳 用
Slides[0]作為標題,然後按收入順序每個地區添加一個幻燈片,每個都有一個32點的粗體標題和三段落,儲存為quarterly.pptx。
陳述IronPPT版本和目標框架。 成員可以在版本之間更改。
較佳 使用IronPPT 2026.10.1在.NET 9上,並在第一次IronPPT呼叫之前從IronPPT_LICENSE_KEY分配密鑰。
請求完整文件。 片段可以省略using IronPPT.Models;指令,提供Slide、Text和Image。
較佳 返回整個Program.cs,其using指令和許可證行,準備好直接構建。
步驟 7:驗證您收到的內容
以下每一個錯誤在2026.10.1中都是可重現的。
- 使用
AddSlide添加標題幻燈片:每個新的PresentationDocument從開始就有一個使用標題佈局構建的幻燈片。 一個程式如果額外新增其自己的標題幻燈片,即會保存一個從空白幻燈片打開的簡報。將標題寫在Slides[0]上,或者首先添加每張幻燈片然後刪除原始的,因為刪除簡報的最後一張幻燈片會引發InvalidOperationException。 - 為整個文檔新增文本:
PresentationDocument.AddText將其文本附加到最後一個幻燈片上的最後一段,並且PresentationDocument.AddTextBox為文本框創建了一個新幻燈片。 通過Slide方法添加內容。 - 用字符串參數設置
AddText的結果風格:返回的文本沒有風格物件,因此設置其屬性會引發NullReferenceException。 技能文件的樣式配方進行了該呼叫。 分配一個新的TextStyle代替。 - 用
FontFamily選擇字體:保存的運行不包含字體。LatinFont將字體寫入文件。
使用IronPPT重新打開的簡報返回其幻燈片計數及文本正確無誤。 從ppt/slides/slideN.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.
使用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調用創建了其自己的150x100點文本形狀且不設置位置,因此形狀將從幻燈片佈局中繼承其位置。 AddParagraph將其段落添加到幻燈片的最後一個文本形狀。- 新簡報的第一張幻燈片在
AddText添加的文本旁邊保留了空的標題和副標題佔位符。 - 圖像
Position、Width和Height為點數。 沒有設置解析度的400x200像素PNG,沒有設定大小的情況下被添加,成為300x150點,其像素大小為96 DPI。 - 在重新打開的簡報中,相同屬性將保存的EMU數字以點數返回,為設定值的12,700倍。
FontSize用Point設置為32寫了一個32點的大小,並且IsBold寫了粗體。- 通過
TextStyle.Color顏色的每次執行因元素無效的子元件錯誤而未通過驗證,無論是命名還是十六進制色彩。簡報的無顏色文本不會出現驗證錯誤。
可重現的結果
測試由一個提示組成,您不寫程式碼。 在一個空資料夾中開啟新會話,貼上提示,並將結果與通關標準進行比較。
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.
輸出
應用程序未編輯的readback.md列出其幻燈片表格和檢查,兩個簡報都在應用程序儲存它們時可用,qbr.pptx和qbr-board.pptx。 以下數字來自獨立閱讀保存的PPTX部件。

未經編輯的應用程式以其自己的PNG編碼器繪制的西區圖示的灰色版本,並將其放置在qbr-board.pptx中。
- net9.0的Release構建完成,沒有警告也沒有錯誤。
- qbr.pptx以請求的順序持有七張幻燈片,沒有空白的。
- 應用程式在指南的列表調用無效後,調用Remove來移除新簡報開始時的幻燈片。
- 每個地區的標題都是32點粗體。
- 北部和東部的收入線為綠色,南部和西部為紅色。
- 兩個簡報中的所有八個地區幻燈片將圖表放在x 360和y 140點,大小為320x160點。
- qbr-board.pptx持有六張幻燈片,西區180K低於目標,緊接著標題。
- 只有“後續步驟”幻燈片在董事會簡報中隱藏。
- 應用程序從磁碟打開qbr.pptx構建董事會簡報,並通過設置其幻燈片的Index屬性來移動西區。
- 應用程序在董事會簡報中的西區幻燈片攜帶了應用程序寫入的圖表PNG的確切字節。
- 應用程序的報讀符號符合22個檢查中的22個。
- 獨立閱讀符合其60個檢查的全部。
- Open XML SDK驗證器在每個簡報中報告了六個錯誤,每個有顏色的執行都會有一個。
- 專案資料夾中、其Git歷史或Claude Code會話文件中都沒有包含授權密鑰的文件。
- 啟動提示將其十一條規則寫入新的CLAUDE.md並將skill.md安裝為專案技能。
- 一些步驟與頁面上運行的不同。 第1、3、5和7步提示在相同會話中在接受提示後執行。
什麼過關
- Release構建完成,無需手動編輯。
- 當您自己讀取文件時,qbr.pptx在第6步設定的順序中有七個幻燈片,沒有空白的。
- 每個地區幻燈片包含其標題、三個評論段落、收入線和一個在要求的位置和大小的圖表。
- qbr-board.pptx有六張幻燈片,直接在標題後面是目標差距最大的地區,而“後續步驟”幻燈片則被隱藏。
- readback.md從保存的簡報中取出每個實際值,並列出需要不同方法的每一步。
- 專案資料夾中的搜尋找不到包含授權密鑰的文件。
運行記錄
- 所有運行使用一台Windows 11 x64桌面,配備Core i9-14900KF和64 GB記憶體。
- 本指南的專案目標為net9.0並固定
IronPPT2026.10.1。 - 指南的持續時間是其頁面上提示的日誌時間之和,而本指南的行只計算接受提示。
- 最後測試在2026年10月16日用於表格中的每個指南。
| 指南 | 助手和版本 | 模型 | 時長(分鐘) |
|---|---|---|---|
| 此指南 | Claude Code 2.1.277,一次會話,允許提示關閉 | Claude Opus 5 | 18.2 |
| Claude Code | Claude Code 2.1.277,提示 3 在計劃模式 | 聖詩5與Opus 5規劃 | 33.3 |
| ChatGPT Codex | Codex CLI 0.160.0 | GPT-6 Luna | 22.2 |
| GitHub Copilot | Copilot CLI 1.0.98,在計劃模式下的提示3、問題主體和審查於其各自的會話中 | GPT-6 Luna,由Auto為其撰寫 | 16.1 |
| Cursor | 光標CLI 2026.10.14,無頭,在計劃模式中的提示3曾啟用並一直啟用至提示5至7 | 作曲2.5 | 15.4 |
| Google Antigravity | 反重力CLI 1.4.0,跳過許可提示 | Gemini 4 Argon (中等) | 47.4 |
代理特定指南
以下每個指南將這些步驟應用於一個工具和一個演示任務。
- 使用IronPPT與Claude Code為訓練課程手冊新增樣式化文本
- 使用IronPPT與ChatGPT Codex為每週銷售展示從範本構建
- 使用IronPPT與GitHub Copilot為不動產列表簡報新增照片
- 使用IronPPT與Cursor為學校的Open XML SDK報告簡報生成器移植至IronPPT
- 使用IronPPT與Google Antigravity為一項建立專案狀態簡報供下載的網頁應用程式
疑難排解
- IronPPT許可證密鑰如果
Save拋出許可權異常 - 工程支援請求如果保存的簡報與程式碼不同且幻燈片編輯部分無法解釋原因
- 管理圖像如果圖片不在程式碼放置的地方
問題?
如果您有任何疑問,請聯繫support@ironsoftware.com
Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。