如何使用IronWord與ChatGPT Codex

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

當公司更改名稱時,法律團隊會收到一份簽署合約的資料夾來更新。 舊名稱會出現在正文段落、當事人表格、大寫標題和頁面頁眉中。 Word也可以將名稱存儲在多個格式化運行中,例如多年前某個片段被加粗。 在每個檔案上進行的標準查找和替換只修復了一些情況,而對於其他情況則保持不變且沒有警報。

ChatGPT Codex是來自OpenAI的編碼代理。 在一個倉庫內,它編輯文件,執行諸如dotnet run的命令,然後總結變更。 一個代理服務於終端、IDE、ChatGPT桌面應用和雲端任務。 IronWord是來自Iron Software的.NET程式庫,可以開啟現有的Word文件作為段落、運行和表格的對象模型,讓代碼可以編輯和儲存,而不需微軟Office。

Codex處理一個合約積壓,使用一個真實依據清單。批量提示寫一個CSV,每份合約一行,因此每個Codex報告的計數都有文件支持。

快速開始
NuGet使用NuGet安裝

PM > Install-Package IronWord

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

在包含合約文件夾的.NET控制台專案中啟動Codex,並在任何編輯前請求一份清單。

$ironword Add the IronWord 2026.10.4 NuGet package to this console project.
Then have Program.cs open every .docx in Contracts/sample/ without changing it.

For each file, write one row to out/quickstart.csv with these columns:

- file
- body count, how often "Northwind Traders" appears in the body text
- table count, the same name counted separately in every table cell
- the exception type, when the file fails to open

Print the totals by reading that CSV back.
Program.cs reads the key from IRONWORD_LICENSE_KEY itself.
Don't print the key's value, and don't list environment variables.
Nothing gets saved here, so an unset key is no reason to stop.
Build and run it with at most three repair attempts, then tell me the result.
Text


什麼是ChatGPT Codex,它如何融入.NET Word文檔工作?

安裝步驟在Codex CLI文件中,版本更新發佈在開源倉庫。

Codex了解IronWord從訓練數據和提供的文件,而新的版本可以使兩者過時。 2026.10的版本通過流和非同步調用進行加載和保存。

如何編寫IronWord提示並設定Codex?

有效的批量提示命名輸入、名稱的每個位置、輸出、證明、唯真實信息以及限制。

OpenAI的語言模型為何產生幻覺論文追溯自信的錯誤答案到訓練和評估中獎勵猜測,在更名工作中猜測每份合約都是乾淨的。

Codex在工作目錄和倉庫根目錄之間每個目錄中的.agents/skills中尋找技能。 儲存為.agents/skills/IronWord/SKILL.md時,IronWord的skill.md解析了$ironword提及。

在任何工作之前,Codex在路徑中從倉庫根到工作資料夾的每個目錄中最多讀取一個AGENTS.md。 距離工作資料夾最近的文件具有優先權。 /init命令起草了一份起始的AGENTS.md。

Give this repository a top-level AGENTS.md with a Contract rebrand section.
List these rules in it:

- No DOCX library other than IronWord is allowed.
- IronWord's package is IronWord, and its namespaces are IronWord and IronWord.Models.
- The ironword skill in .agents/skills/ironword/ is one API reference.
- https://ironsoftware.com/word/csharp/llms.txt is the other.
- Contracts/inbox/ and Contracts/manifest.csv are read-only.
- Rebranded copies go to out/rebranded/ under their original names.
- IRONWORD_LICENSE_KEY holds the key, and its value never appears in output, logs or files.
- Checking the variable means its presence and length, nothing more.
- Any count you report is read from a CSV written in the same turn.
- The reply names that CSV.
Text

如何要求Codex添加IronWord並檢查許可證?

Print the IronWord PackageReference from ContractRebrand.csproj and the version restore resolved.
Then quote every IronSoftware entry that dotnet list package --include-transitive prints.
Leave the package references exactly as they are.
Text

IronWord 2026.10.4引用IronSoftware.Abstractions 2026.1.2、IronSoftware.Common 2026.4.2和IronSoftware.System.Drawing 2026.11.3。恢復期間還列出了IronSoftware.Drawing.Abstractions 2026.1.2。構建過程將Windows、Linux和macOS的本機LayoutEngineInterop庫複製到runtimes資料夾中。 OpenXML衝突頁面涵蓋了在2025.7.13之前的版本中與較新DocumentFormat.OpenXml的衝突問題。在固定之前,請檢查IronWord更新日誌。

沒有密鑰時,開啟、讀取和替換成功,但是每次保存超載(包括非同步保存)都會拋出一個LicensingException,信息顯示需要生產許可證。

Add Startup.ApplyIronWordKey and call it first in Program.cs.
It copies the IRONWORD_LICENSE_KEY value into IronWord.License.LicenseKey.
It also reports whether License.IsLicensed is true.

Add a --dry-run switch that opens and edits in memory and never saves.
Then run the sample twice with the variable removed:

1. Run it once with --dry-run.
2. Run it once copying each file to out/licence-check/ through SaveAs.

Clear the variable inside each child process only, never for the session.
Write out/licence-check.csv with the columns run, file, call, exception type name and message.
Tell me which calls threw.
The licensing exception type isn't public, so catch Exception and record its GetType().FullName.
Stop after three repair attempts.
Text

許可證密鑰頁面還涵蓋了Web.config、App.config和appsettings.json。

文字替換可以在Word文檔的哪些部分生效?

Create Services/MentionScanner.cs.
For one DOCX it returns a count for each of these:

- "Northwind Traders" in body paragraphs
- "Northwind Traders" in table cells
- the name in upper case
- the name inside "Northwind Traders Pension Trust"
- the name in headers and footers
- the old notice address
- the Fax notices paragraph

The body and table cell counts leave out the pension trust name.
IronWord has no header or footer model.
For that column only, read word/header*.xml and word/footer*.xml with System.IO.Compression.

Then run it over Contracts/inbox/ into out/inventory.csv.
Mark files that fail to open as Unreadable.
List every file whose counts differ from manifest.csv.
In that comparison, the body count is body_mentions plus split_run_mentions.
Text

內建的探測代理在真實文件上測試替換效果。

Create a scratch console project under scratch/replace-probe/ yourself.
Add a Compile Remove line for scratch/** to ContractRebrand.csproj.

Then ask the explorer agent to use that project.
It finds which parts of a contract the document-level ReplaceText call changes.
It tests copies of the Contracts/sample/ files in memory, with these four cases:

- a name split across runs
- a table cell
- the upper-case title
- the pension trust

The header has no object in the API, so the explorer answers that one from IronWord.xml.
It changes nothing under Services/ or in Program.cs.

Write the five answers to out/replace-reach.csv.
Beside each answer, quote the ironword skill or IronWord documentation.
Where a page and the test disagree, say so.
Text

在2026.10.4的校準給出了這些內存中的結果。

位置文檔級別的替換哪些可以到達
正文,單個運行已替換文檔調用
正文,分多個運行已替換文檔調用
表格單元未更改ReplaceText在每個TableCell上
大寫標題未更改(區分大小寫匹配)以大寫形式進行第二次調用
年金信託名稱更名(普通子字符串匹配)首先替換佔位符,然後還原
頁首或頁尾不在對象模型中報告它,然后手動編輯

分割運行行有一個副作用。 如名稱存儲為加粗North後接普通wind Traders,變為一個加粗運行,讀為Contoso Ltd.

基於文檔的ExtractText 構建的檢查(只返回正文段落)通過了一份仍使用舊公司名稱的當事人表格合同。 FindText錯過了一個分割運行匹配,因為它只匹配持有整個短語的文本元素。

如何在一個文件夾的文檔中進行文字替換?

Have the worker agent write Services/Rebrander.cs.
It applies every rule in Contracts/README.md to Contracts/inbox/.
It builds on the explorer's findings and follows these rules:

- Replace inside each table cell as well as the body.
- Keep the pension trust intact.
- Delete the Fax notices paragraph.
- Leave header and footer parts as they are, since IronWord can't edit them.
- Report those contracts as HeaderFlagged.
- Save each copy to out/rebranded/ with SaveAs.
- Never call Save() on a document opened from inbox/.

Add a --sequential mode that rescans the saved copies with MentionScanner.
It writes out/sequential.csv with these columns:

- file
- status from the README, always one of its four
- mentions left per location
- milliseconds
- header_lost, set to yes when a copy lacks a header or footer part its original had

The header_lost column is reported on its own and never changes a status.
Tell me the status counts.
Text

在IronWord 2026.10.4中,保存包含表格的已加載DOCX會丟棄表格內和第一個表格後的任何段落的所有文字編輯。 磁碟上的副本保留了舊文字,未引發異常,內存中的文件仍顯示替換。 第一個表格前的編輯仍然存在,正如用新的TableCell替換的單元格一樣。 這些合同將簽名放在參加者表格後,因此內存檢查通過了保存簽名未更改的副本。

無參數的Save被記錄為覆蓋已加載文件的源文件,因此批處理不應調用它。 移除文本指南顯示傳真規則背後的段落移除。

在校準中,讀取零字節文件拋出NullReferenceException,進而是文本文件、截斷包和隨機字節包每一個都拋出FileFormatException,來自模糊命名空間,信息為文件包含損壞數據。 系統.IO型別捕獲器未抓取它。 每個文件捕獲Exception,並記錄其類型。

副本使用SaveAs,IronWord的故障排除頁面為保存後消失的頁首命名。

Check whether SaveAs lost a header anywhere in this backlog.
IronWord's troubleshooting page header-disappears-after-saveas reports that in one environment.

For every HeaderFlagged file, compare the inbox original with its out/rebranded/ copy.
Look at the word/header*.xml and word/footer*.xml parts.
Write out/header-check.csv with these columns:

- file
- header parts before
- header parts after
- whether each part is present with its text unchanged

If a part went missing, rebrand that contract again from its inbox original.
Write it with the Save overload that takes the out/rebranded/ path.
Don't use the parameterless Save().
If the part is still missing, record it and stop.
Tell me which files lost a part.
Text

如何並行處理文件夾的文檔?

非同步調用無阻塞地進行文件I/O,但文件說明指出解析和序列化仍然是同步的,而且一個文件實例不是線程安全的。

Add a --parallel mode that works like this:

- It runs Task.WhenAll over the inbox.
- Each task holds a slot of a SemaphoreSlim whose size comes from --concurrency.
- Then it awaits WordDocument.LoadAsync and SaveAsAsync on its own WordDocument.

Run the mode three times:

1. At concurrency 1 into out/parallel-c1/.
2. At concurrency 4 into out/parallel-c4/.
3. At Environment.ProcessorCount into out/parallel-max/.

Write out/parallel-compare.csv with the columns file, folder and a yes or no.
The yes or no says whether the extracted body and cell text match out/rebranded/.
Log each run as a new line of out/runs.csv.
Give it the mode, concurrency, elapsed seconds and match count from out/parallel-compare.csv.
Tell me the quickest setting in runs.csv.
Text

在校準中,開啟和編輯內存中的收件箱(包括四個無法讀取的文件)花費4.8秒串行、1.4秒在4的限制下,與16的限制下1.8秒,而SaveAsAsync添加了14.4、5.5和4.7秒。 保存是限制步驟。

如何診斷仍顯示舊文本的文件?

Codex接受圖片,通過新的會話使用-i標籤(--image)或使用codex exec resume,或粘貼到編寫器中。

I attached the first page of out/rebranded/MSA-1050.docx as an image with -i.
Its header still names Northwind Traders.
Look at the image, then explain from the file itself why the batch left that text.
Tell me whether out/sequential.csv already flags this file.
Don't change any code.
Text

正確答案指的是頁首部分和文件的HeaderFlagged行。

如何端到端追蹤不正確的批次輸出?

Find out why the nightly job passed contracts that legal later flagged.
The log reports 0 contracts still naming Northwind Traders.
Contracts/legal-review.csv lists contracts where legal still found the old name.
It was in the party table or an upper-case title.
The file also lists a pension trust that was renamed.

Send the explorer agent through Jobs/NightlyRebrand.cs and Logs/nightly-2026-10-07/ first.
Then write your own report in out/nightly-diagnosis.md with these parts:

- why the job's own check passed them
- the smallest fix
- the command that proves the fix

Don't run or edit any code.
Text

診斷應該引用工作標記合約清除的那一行。

如何將一次性代碼轉變為可重用的、經過測試的組件?

Put the worker agent on a RebrandJob class, built like this:

- Install the Microsoft.Extensions.DependencyInjection package.
- Have its container resolve RebrandJob.
- Set it up through a RebrandOptions record with inbox, output folder, concurrency and dry run.
- Keep every README rule, the header check and the per-file CSV.
- RebrandJob.cs stays under 180 lines, with XML doc comments.

The README rules cover body and cell replacement, upper case and the pension trust guard.
They also cover the address and the fax deletion.
Run the job over the whole inbox into out/final/ and out/final.csv.
Then tell me whether every status matches manifest.csv.
Also confirm no copy keeps an old name, old address or fax paragraph.
Old names in a copy's header or in the pension trust don't count.
Text

重構可以刪除規則並仍然構建。

Add an xUnit project at tests/ContractRebrand.Tests.
Exclude it from the main project's compile items, and join both projects in a solution file.

Write tests on real inbox files that check these:

- a split-run contract comes back with no old name
- a table contract is clean in its cells
- a pension trust mention survives
- a header contract is HeaderFlagged
- the zero-byte file is Unreadable without stopping the batch
- 20 files rebranded in parallel equal their sequential copies

Assert on extracted text and statuses, never on DOCX bytes.
Keep test copies in out/tests/work/.
Run dotnet test on the solution with a trx logger into out/tests/.
Report the totals from the trx file.
Text

OpenAI的自定義提示文件廢除保存於~/.codex/prompts中的提示,偏向於技能,其中經常性問題屬於技能。

$ironword Look in the installed IronWord.xml.
List the WordDocument members that load or save a document, and answer these:

- Which ones are asynchronous?
- Which one overwrites the source file a document was loaded from?

List only members you can call from a line that compiles in a probe under scratch/.
Also name any member anywhere in IronWord.xml that is documented but doesn't compile.
Check by compiling only.
Don't run Save() on any document loaded from Contracts/inbox/.
Then show the line in RebrandJob that keeps Contracts/inbox/ untouched.
Text

如何在另一個文件積壓中重複使用這些提示?

名字、路徑和規則改變后,這些提示適合下次積壓,IronWord AI 編碼助手指南涵蓋了所有五個助手的設置。

在實際運行中,這些提示產生了什麼結果?

提示按順序在一個Codex會話中運行。 .NET 9項目包含124份合約和預期狀態與計數的清單,每個Release構建都成功。 我們的掃描儀再次掃描每個保存的副本,測試在一個新的克隆中再運行。

  • 在重命名前,清單上的124個文件和4個非DOCX文件都符合實際情況,並標記為無法讀取。
  • 在順序重命名后,保存的120個副本中,當事人表格上方沒有114個舊名稱,其中包括分成多次運行的22個。
  • 沒有13個大寫標題、38個舊通知地址或57個傳真段落保留。
  • 所有9個養老信託名稱保持完好。
  • 舊名稱仍然存在於28個參加者表格和114個簽名中,因為保存丟棄了這些編輯。
  • worker的sequential.csv為每個文件給予清單狀態,重新命名104個,標記為HeaderFlagged的10個,NoChange的6個和Unreadable的4個,但其自身計數列仍顯示114個簽名和28個表格提及。 狀態記錄是檢測而不是替換,Codex自身報告了這一點。
  • 在10個樣本文件中,快速啟動報告了19個正文和2個表格提及,與清單上的16和2相比。其正文計數還拿走了2個單元格提及和養老信託名稱。
  • 沒有密鑰的情況下,乾跑在內存中編輯了所有9個可讀的樣本文件。 保存運行在SaveAs上為它們拋出了LicensingException。
  • 在1、4和32的限制下,並行運行耗時11.456、7.825和5.830秒。 每個文件夾中的120個可讀的副本與順序的一致。
  • 夜間診斷追溯了發現結果至工作的區分大小寫ExtractText().Contains檢查及其文件級別替換。 它沒有引用行號,且其證明指令針對一個尚不存在的測試項目。
  • 重構保留了RebrandJob.cs的68行中的每條規則,其out/final副本與out/rebranded匹配。
  • final.csv符合清單狀態但標記了118行不完整,Codex報告內容檢查失敗。
  • Codex的運行和新的克隆各通過了6次測試中的4次。 分割運行測試在簽名上失敗,表格測試在參加者表格單元格上失敗。
  • API答案列舉了四個加載、七個保存和五個非同步成員,並將無參數Save命名為覆蓋源的那個。
  • 它正確地命名了四個無法編譯的記錄成員,這些是接受字節和字符串的構造函數、FlushModelToBytes、段落中的ReplaceTextAcrossRuns和SetNoChangeStatusAsUpdated。
  • 它還列出了字節專用構造函數,這個能編譯,它錯過了五個其他在2026.10.4中失敗的,FromMarkdown、FromMarkdownFile、ExportToMarkdownFile、GetMailMergeWorkingBytes和ApplyCellStyle在表格上。
  • 一些步驟與頁面上運行的不同。 圖像使用python-docx從運行的MSA-1050副本渲染。 夜間工作、其日誌和法律審查文件在調查提示之前被立即添加。

GitHub Copilot指南通過Tables、Rows和Cells讀取其表格來測試保存的聲明。 Cursor指南列舉了IronWord不讀取的DOCX部分。

共享的運行記錄列出了Codex版本、模型、機器和本次運行的時間。


疑難排解


問題?

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

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

閱讀更多

準備好開始了嗎?

NuGet 下載次數 62,392版本:2026.11剛剛發布