如何在ChatGPT Codex中使用IronXL

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

一个共享的收件箱文件夹收集分支发送的内容。 现代XLSX导出与多年前已弃用系统的XLS文件、逗号和分号分隔的CSV文件、制表符分隔的仓库数据转储、加密的工资单工作簿、网页门户导出的HTML文件,以及由上传失败留下的零字节文件相伴而生。 仓库希望将它们都转换为CSV、JSON和XML,并希望了解哪些文件未到达。

ChatGPT Codex是OpenAI的编码代理。 它作为终端程序、IDE扩展、ChatGPT桌面应用程序和云服务发布,并且它们都可以使用相同的ChatGPT帐户登录。 IronXL是Iron Software为.NET开发的电子表格库。

本指南中的每个转换提示都会让Codex在报告之前为每个输入文件写一个结果文件的行,这里的每个转换数据都是从此类文件中统计的。

快速入门
NuGet使用NuGet安装

PM > Install-Package IronXL.Excel

通过在 NuGet 包管理器控制台中运行上述命令安装 IronXL,或在 NuGet 包管理器中搜索该包。

在一个包含一些示例电子表格的.NET控制台项目中打开Codex,并描述转换。

$ironxl Add IronXL to this console project and have Program.cs convert every file in Samples/.

- Save each worksheet as CSV, JSON and XML under out/quickstart/<file name>/.
- Log each input file as one line in out/quickstart-results.csv.
- Give each line the sheet names, data rows per sheet and output files.
- For a file that fails, add the exception type to its line.
- Read that CSV back and print how many files succeeded and how many failed.

The license key is in IRONXL_LICENSE_KEY.
Build and run it, and fix whatever breaks.
Text

$ironxl提到在Codex编写代码之前加载IronXL的技能。



什么是ChatGPT Codex,它如何适用.NET电子表格工作?

Codex在所授予的权限范围内执行指定任务。 对于转换流水线,它编写转换器,运行它以处理收件箱,打开它生成的文件,并在错误时编辑代码。 从Codex库中用npm install -g @openai/codex安装CLI,并查看Codex CLI页面以获取终端信息。

OpenAI的安全指南要求对Codex输出进行与人工拉取请求相同的目标检查和差异审查。 在这个流水线中,发明的成员中断了构建,错误的转换显示为与清单不匹配的结果行。

Codex可能每次以不同的方式布置转换器,但IronXL需要为给定文件返回相同的表格和数值。WorkBook.Load可以打开XLS、XLSX、XLSM和XLTX文件,以及CSV和TSV文件,如加载指南所列。

如何撰写IronXL提示并设置Codex?

转换提示说明读取哪个文件夹,如何打开每种文件类型,哪里的每个输出去往哪里,结果文件的一行包含什么,以及什么算作证据。 任何遗漏的项目都将成为代理为您做出的决定。

组件弱提示强提示
输入转换电子表格Inbox/中的每个文件,XLS、XLSX、CSV和TSV
加载未说明WorkBook.LoadCSV来自out/inventory.csv的分隔符
产出将它们保存为CSV每个输入文件在out/converted/下的一个文件夹中,每张表对应CSV、JSON和XML
错误未说明任何抛出异常的文件会得到一行结果,其异常类型
证明检查是否成功out/convert-results.csv的每一行都与Expected/manifest.csv一致
约束条件None*保持Inbox/不变。 任何输出中都没有密码。

OpenAI的幻觉研究发现培训和评估奖励猜测,在转换工作中,猜测可能在结束总结中出现。

Codex在从工作目录到库根目录的.agents/skills文件夹中寻找技能。 技能是一个SKILL.md以名称和描述开头的文件夹。 IronXL发布其skill.md为ironxl,因此将其保存为.agents/skills/ironxl/SKILL.md以使$ironxl解析。 即使没有提到,Codex仍然可以根据任务与技能描述的匹配来自行选择技能,而IronXL的描述中列出了XLSX、XLS、CSV、TSV、JSON和XML之间的转换。

AGENTS.md包含常设规则。 Codex从库根目录开始收集这些文件,一直走到会话开始的文件夹,并且如果两个文件冲突,离该文件夹更近的文件优先。

Write a root-level AGENTS.md with a section called Spreadsheet conversion.
It should hold these rules:

- IronXL (NuGet IronXL.Excel, namespace IronXL) is the only spreadsheet library allowed.
- API names come from the ironxl skill in .agents/skills/ironxl/.
- The index at ironsoftware.com/excel/csharp/llms.txt is also a source for them.
- IRONXL_LICENSE_KEY holds the license key, which is never echoed or saved.
- Inbox/, Expected/ and config/ are read-only.
- Passwords from config/known-passwords.csv never reach source code, an output or a log.
- Only a per-file results file written in that turn can back a count, total or timing in a reply.
- A reply that gives such a number names that file.
Text

在AGENTS.md中预期一个新章节,而由于这次转换任务无任何内容,回复中不会有数字。

如何请求Codex添加IronXL并转换第一个文件夹?

在任何其他操作之前检查软件包。

Tell me about the IronXL package, and don't change any package reference.

1. Print the IronXL.Excel PackageReference from SheetConvert.csproj and the version restore resolved.
2. Run dotnet list package --include-transitive and copy out every line that isn't IronXL.Excel itself.
3. Say whether anything in that graph needs Microsoft Office, Office Interop or a native library on Linux.
Text

IronXL.Excel 2026.10.1直接依赖于IronSoftware.Common 2026.4.2和IronSoftware.System.Drawing 2026.8.2。在.NET 9上,传递列表中除了IronXL.Excel多了30个软件包,其中没有Office或Interop,构建输出中的每一个DLL,包括运行时下的平台文件夹,都是托管程序集。 保留Codex所报告的版本以便后续提示中使用,并在IronXL更新日志中选择一个版本。

如果没有密钥,每次IronXL加载都会失败。 对28文件的收件箱而言,这将意味着同样失败的28个副本,因此下面的保护程序会在触及任何文件前退出。

Put the license setup in Startup.ApplyIronXlKey and call it before any other line of Program.cs runs.
If IRONXL_LICENSE_KEY is missing or License.IsLicensed is false, write one line to stderr.
Then exit with code 2 before opening any inbox file.
Run the program twice, once as it is and once with the variable unset for that run only.
Give me both exit codes.
Text

页面许可证密钥涵盖试用密钥和IronXL也读取的配置文件。

在转换器存在前,找出文件夹里有什么。 OpenAI文档中记录Codex内置的浏览器是一个面向代码库浏览的重读型代理,适合没有编辑的调查。

Ask the explorer agent to survey Inbox/ without changing anything.
For each file it should report:

- the extension and the size in bytes
- the first eight bytes in hex
- what those bytes say the file really is (OOXML zip, OLE2 compound file, plain text, HTML, or unknown)
- for a text file, the separator in its header line

When the explorer reports back, save its findings as out/inventory.csv with one row per inbox file.
Then list every file whose bytes disagree with its extension.
Text

XLSX是以PK开头的ZIP档案,而XLS是以D0 CF 11 E0开头的OLE2复合文件。 调查标记了一个名为.xlsx的逗号分隔文本文件和一个名为.xls的门户导出文件,该文件包含一个HTML表格,不能通过首字节识别出零字节的Newcastle文件或随机字节文件。 它还标记了两个加密的工作簿,因为一个加密的XLSX是一个具有旧版XLS相同签名的OLE2容器。

Create Services/InboxConverter.cs with a Convert(string path) method.
Convert returns a FileResult record.
The record holds the file, status, reason, sheet names and data rows per sheet.
It also holds the output paths, and the exception type and message.

Convert follows these rules:

- Open .xls and .xlsx files with WorkBook.Load.
- Open .csv and .tsv files with WorkBook.LoadCSV, using the separator recorded in out/inventory.csv.
- Save every sheet with SaveAsCsv, SaveAsJson and SaveAsXml into out/converted/<file name without extension>/.
- Keep going when a file throws.

Add a --convert mode that writes out/convert-results.csv.
Run it, and give me the status counts from that file.
Text

此阶段有四行状态错误。 零字节文件和名为.xlsx的文本文件算作转换成功,而两个加密的工作簿算作失败,已知密码的工资表文件以及属于Protected的奖金池文件。 后续提示会修正这四个问题。

IronXL在哪里写入每张工作表?

一个工作簿保存不会写入您传递的路径。 如果一张订单表是工作簿的唯一表,使用SaveAsCsv和路径out/x/orders.csv会相应写出orders.Orders.csv,其中文件名后接表名,从不创建orders.csv。转换指南文档了每个工作表一个文件的CSV、TSV、JSON和XML,并且我们用2026.10.1测量了流水线依赖的细节。

  • 单张表仍会加后缀: 从CSV或TSV加载的工作簿有一张名为Sheet0的表,因此customers-uk.csv会变成customers-uk.Sheet0.csv。
  • 表名保持不变: 收件箱的Q3 Summary表会给出一个带空格的文件名,法语表名保留其重音字母,因此下游脚本必须引用路径。
  • 工作表写入器行为不同: 以CSV、TSV、JSON或XML名进行简单的工作簿保存也按表分割,而WorkSheet.SaveAsCsv和其他工作表写入器则正好生成所给的路径。
  • 每种格式都有自己的形状:CSV以UTF-8字节顺序标记开始,JSON是一个每个值都是字符串的行数组,XML为每个位于xsi:type的单元格给出ColumnN元素,例如xs:double。 不符合XML命名规则的表名会被转义,因此Q3 Summary会变成元素Q3_x0020_Summary。

由于CSV可以包含引用换行符并以空行结尾,统计其行数会给出错误的行数。 如结果文件一样从工作表本身统计数据行,并列出IronXL写入的输出路径。

为什么转换后的CSV丢失了前导零?

导入转换数据的团队可能会以图片形式报告问题。 当会话以codex --image开始时,Codex接受图像,并且CLI也允许您粘贴一个图像到撰写器中。

I've attached a screenshot with codex --image.
The customer accounts team took it from their import preview of the converted customers-uk file.

1. Read the picture and compare it with Inbox/customers-uk.csv.
2. Tell me which values changed between source and output, and which IronXL setting changed them.
3. Fix the conversion and rerun it for that file.
4. Write out/accountno-check.csv with one row per customer.

Give each row of that file these columns:

- source AccountNo
- converted AccountNo
- whether they match
Text

截图显示未找到的三个账户为123、4567和9。源文件中分别为000123、004567和000009。LoadCSV有一个默认为true的convertFieldValues参数,使任何看似数字的字段转为数值,导致丢失前导零。 传递convertFieldValues: false保持每个字段为分支编写的文本。

为什么CSV在另一台机器上加载不同?

LoadCSV根据listDelimiter参数分割列,当参数为空时,IronXL回退至当前文化的列表分隔符。 在我们的en-CA机器上,分隔符是逗号,因此来自里昂的分号文件在每个小数逗号处被裁剪为两列。 在de-DE环境下相同的调用将其正确地分割。 对于CSV文件,WorkBook.Load表现相同。 CSV读取指南展示了显式格式。

分隔符只是问题的一半。 如果保留字段转换打开,IronXL也会使用当前文化解析数字。 在en-CA上,使用分号分隔符的LoadCSV将里昂价格4,20读取为420,没有错误,因为逗号在那是千位分隔符。 在de-DE环境下它读取为4.2。

Prove the text survived conversion for every .csv and .tsv in Inbox/.

1. Rerun --convert so every file goes through the fixed conversion.
2. Compare each source field with the same field in the converted CSV.
3. Write out/text-fidelity.csv with one row per file.
4. Load orders-lyon-2026-09.csv again, first under de-DE and then under en-US.
5. Use a semicolon separator for both loads, and leave convertFieldValues at its default.
6. Add two rows to out/text-fidelity.csv giving the UnitPrice of the first data row under each culture.

Give each per-file row these columns:

- separator
- source columns
- output columns
- fields compared
- fields that differ
- first difference
Text

IronXL对于格式化单元格写入哪个值?

工作簿的CSV和JSON写入器写出每个单元格显示的文本,与其FormattedCellValue相同,因此数字格式决定什么到达仓库。 XML写入器则写出存储值及其类型。 我们在由openpyxl写的XLSX和收件箱的Derby XLS上测量了这一点。

存储值翻译格式CSV,en-CACSV,de-DEXML
1234.5#,##0.00"1,234.50"1.234,501234.5
2.3456780.002.352,352.345678
0.2560%26%26%0.256
123000000000123000123123
2018年3月1日m/d/yy h:mm3-1-18 0:003.1.18 0:002018-03-01T00:00:00

四舍五入减少了数字,没有报告。 在0.00格式下,重为0.004的重量以0.00出现。文化也会影响输出。 随附的XML文档说明保持CSV写入器的分隔符为空以使用系统默认,在de-DE环境下默认写出分号。 传递逗号作为分隔符仅改变分隔符。 在General格式下的Derby价格仍然输出为"33,84"。

在en-CA环境下,大多数工作都被收件箱隐藏,因为其他工作簿保留数字为General格式,日期为yyyy-mm-dd。 由IronXL写的Derby文件是个例外。 在Codex为其转存的CSV中,所有70个日期都像最后的表行一样输出,为两位数年份,使用en-CA日期分隔符,而en-US则变为3/1/18 0:00。当仓库需要存储值时,从每个单元格的Value格式化为CultureInfo.InvariantCulture中构建CSV。 在en-CA、de-DE和fr-FR下,这给出了1234.5、2.345678和2026-09-20。

为什么损坏的文件转换没有错误?

当WorkBook.Load无法作为工作簿读取文件时,它会尝试作为CSV读取。该回退解释了收件箱中的几个结果。

收件箱文件加载结果记录为
零字节.xlsx一张空表,无例外无法读取,空
以.xlsx存储的逗号分隔文本加载为CSV,有两列中九个数据行无法读取,内容不匹配
以.xls存储的HTML表格抛出FileLoadException。 无引号字符的副本加载为一个单元格无法读取,内容不匹配
以.xls存储的随机字节抛出FileLoadException,内部AggregateException"Excel加载失败,然后CSV回退也失败"无法读取,格式未知
真实.xlsx的前40%抛出FileLoadException,原因是内存不足,内部SharpZipBaseException"Unexpected EOF"无法读取,截断

前两行是危险的,因为仅捕获异常的转换器将其报告为成功,并将空表或重命名的文本文件运送到仓库。

Add a byte check to InboxConverter.
Expected/README.md defines when a file counts as Unreadable and which reason to record.

- Before IronXL opens a file, compare its leading bytes with its extension.
- On a mismatch, set the status to Unreadable.
- Give it the reason empty, content-mismatch or unknown-format, as the README defines them.
- A file that starts like a valid zip but still fails to load is truncated.
- Keep the exception type for every file that throws.

Leave the encrypted workbooks for the next turn, and add no password handling yet.
Rerun --convert, then compare out/convert-results.csv with Expected/manifest.csv.
List every row whose status or reason disagrees.
Text

IronXL如何处理密码保护的工作簿?

收件箱中出现两种保护类型,IronXL以不同方式处理它们。

加载时未提供密码时会抛出ArgumentNullException,提供错误密码时会抛出SecurityException,而ProtectSheet仅锁定编辑。 收件箱的工作簿保护目标在没有密码的情况下加载并转换。 AI编程助手指南全面比较了这两种类型,密码指南提醒文件格式无法在不尝试打开文件的情况下测试保护。

Handle the two encrypted inbox workbooks.

1. Load each OLE2 .xlsx with its password from config/known-passwords.csv.
2. Give a file with no listed password the status Protected and the reason no-password.
3. Try one wrong password against the payroll file and record the exception type it raises.
4. Rerun --convert and confirm out/convert-results.csv agrees with Expected/manifest.csv on every row.
5. Write out/password-scan.csv with one row per file under out/.
6. Say in each row whether that file contains any known password.

Tell me how many rows of out/password-scan.csv found a password.
Text

DataSet循环往返是否返回相同的表?

缺省情况下,循环往返不会返回相同的表。 一个通过ToDataSet将表发送给SQL或Entity Framework并使用LoadWorkSheetsFromDataSet重建工作簿的流水线应测试往返。OpenAI在Codex的文档中将内置的工作代理描述为专注于执行、实现和修复的代理,而/subagents命令则在其运行时切换到其线程。

Have the worker agent add a --roundtrip mode.
For each Converted file it should:

1. Call ToDataSet.
2. Rebuild a workbook with WorkBook.LoadWorkSheetsFromDataSet.
3. Take the values only from that DataSet and never from the source sheet.
4. Save the rebuilt workbook to out/roundtrip/<name>.xlsx and reload it.
5. Compare every cell's text with the source sheet.
6. Write out/roundtrip-results.csv with one row per sheet.

Give each row these columns:

- rows before
- rows after
- cells compared
- cells that differ
- first difference

Fix the round trip until every sheet reports zero differences, and tell me what each fix was for.
Text

我们的校准中28张转换表中有3项数据变化。

  • 标题行消失: 带有true头参数的ToDataSet将第一行转为列名,重建不写入标题行。 每张表都丢失其标题行,5,267个单元格不同。 没有参数的ToDataSet默认为false,保留标题作为数据,避免丢失。
  • 看似日期的文本变为日期: 重建以分配Cell.Value相同方式分析字符串值。 文本2026-09-01回归为DateTime,而汉堡日期10.09.2026(9月10日)在en-CA环境下变成10月9日。 当修复标题问题时,六张表的364个单元格因该原因仍不同。
  • 列类型都是对象: 导出的DataSet中的每列都为System.Object类型,整数作为Double到达。 读取表的代码需要自行转换值。

通过Cell.StringValue重新分配每个文本值,存储为书写文本,阻止日期转换。 DataSet指南展示了转换的两个方向。

如何报告所有转换失败的文件?

结果文件显示哪些文件转换失败,但负责修复收件箱的人也需要分状态详细了解每个失败原因。

I need a written reason for every file that didn't convert.

1. Have each --convert run rewrite out/convert-log.jsonl with one JSON object per inbox file.
2. Build out/failures.md from that JSONL alone.
3. Give each status other than Converted a heading, its count, and each file with its reason.
4. Check the counts in failures.md against out/convert-results.csv and report any mismatch.

Give each JSON object these fields:

- file
- status
- reason
- exception type
- message
- milliseconds
Text

如何端到端调试不正确的转换输出?

只给出了症状,Codex可以在源文件、日志和其他团队笔记中跟随问题。

Finance says every European total has been about a hundred times too high since 2026-10-01.
The job and its inputs didn't change.

Send the explorer agent to find the cause.
Have the explorer read Jobs/NightlyConvert.cs, Logs/, Ops/hosts.md and Feedback/finance-2026-10-07.md.
In out/nightly-diagnosis.md, do the following:

- show the line of the job that produces the inflated totals
- explain why conv-01 gave the right totals
- propose the smallest fix, with a command that proves it on all three branch files

Don't edit any code in this turn.
Text

在修复之前,阅读诊断报告并同意其评估结果。 强有力的答案引用依赖于默认字段转换的LoadCSV调用,连接从德国格式Windows主机迁移到LANG为en_US.UTF-8的容器的过程,并提出保留字段文本并使用分支文件写入的文化解析价格。 我们的校准中,这一更改在两种文化下产生相同的ERP总额。

如何将一次性代码转化为可重用的、经过测试的组件?

当结果文件和清单的每一行一致时,将模式合并为其他服务可以调用的单一作业。

Have the worker agent merge the conversion modes into one ConversionJob.

- Wire it up through Microsoft.Extensions.DependencyInjection.
- Pass it a ConversionOptions record that holds the inbox folder and the output folder.
- The record also holds the passwords file and the formats to write.
- Keep the byte check, the password handling and convertFieldValues: false.
- Clear out/converted/ at the start of each run.
- Stay under 180 lines and add XML doc comments.

Then run it over Inbox/ into out/final-results.csv.
Confirm every row matches Expected/manifest.csv on status, reason, sheet count and data rows.
Text

重构可取消字节检查、密码查找或convertFieldValues设置同时仍能编译。

Add an xUnit project, SheetConvert.Tests, whose tests run ConversionJob on real inbox files.
They should check that:

- branch-summary-q3.xlsx yields nine output files named after its sheets
- customers-uk.csv keeps 000123
- orders-lyon-2026-09.csv keeps 4,20 and six columns
- the zero-byte and HTML files are Unreadable with the README reasons
- bonus-pool-2026.xlsx is Protected
- a DataSet round trip of pricing-2026.xlsx leaves no differing cell

Finish with dotnet test and save its results as a TRX file under out/.
Quote the pass and fail counts from that file.
Text

以输出字节作目标测试不佳,因为保存的XLSX可以在发布间逐字节变化,而每个值保持不变。

将经常重复的IronXL问题保存在库技能中,而不是在~/.codex/prompts/中,OpenAI的定制提示页面已标记为弃用。

$ironxl Look through the IronXL API reference for methods that write CSV, TSV, JSON or XML.
List every such method on WorkBook and WorkSheet.
For each one, say whether it writes one file per sheet or a single file.

1. Check each answer in a scratch project outside this repository.
2. Call each method on a two-sheet workbook, or on one of its sheets.
3. Copy only the files the calls produced into out/api-probe/ and list them.
4. Name the line in ConversionJob that decides each output file's name.
5. Confirm SheetConvert still builds.
Text

如何在另一个电子表格文件夹中重用这些提示?

更改路径,提示即可应用于任何其他电子表格文件夹。 要进行从空文件夹开始的端到端验收测试,请参阅AI编程助手指南。

在实际运行中这些提示生成了什么?

我们在单个会话中将所有上面的每个提示的早期措词发送到Codex,以一个针对.net 9的控制台应用程序为样例。收件箱保存28个文件(单表和多表XLSX、来自两个不同作者的三个老XLS文件、逗号、分号和制表符分隔的文本,一个表格保护的工作簿、两个加密工作簿、以及五个损坏或标记错误的文件) 清单给出每个的预期状态、表数和数据行数,密码文件列出以两个加密工作簿之一。 运行过后,我们用自己的Release版、测试套件的运行和每个收件箱文件的独立转换检查了下述结果。

  • 第一个转换器标记23个文件为转换成功,5个失败。 最终作业在28行的所有项目上与清单一致,其中22个转换成功,1个受保护,5个无法读取。
  • 在字节检查之后、任何密码处理之前,21个文件转换成功,7个无法读取,只有两个与清单不符的行是这对加密行。
  • 文字保真度从五个九个文本文件中的147个不同字段改为所有九个中的0。文化探测以420读取了里昂的单价为en-US,4.2为de-DE。
  • 在截图修复之后,丢失前导零的9个帐户号码恢复,并且60个中的60个与源一致。
  • 在快速入门中,报告了8个样本文件中有7个成功,而随机字节文件抛出FileLoadException。 零字节Newcastle文件被视为成功,Lyon为两列。
  • 密钥保护的退出代码为0有密钥设置而为2无设置。 Codex通过环境访问了密钥,从未在文件或回答中出现。
  • 调查结果包括28行,标记4个不匹配,未识别2个文件。
  • 工资单以其25个数据行转换,奖金池为唯一受保护的行,错误的密码引发SecurityException,并且没有out/下的124个文件包含密码。
  • 往返工作代理写的28表的5,714个单元格对比中差异为0,其中也复制了数位格式。 我们自己的往返过程也发现了0。
  • 某次失败报告列出了5个无法读取的文件和1个受保护文件,与结果文件相同。
  • Codex定位了夜间作业的第27行和en-US环境。 在de-DE下,分支文件给出了ERP总额25632.85、11926.93和14387.26,而在en-US下为这些的100倍。 我们在这一提示之前添加了作业,其日志、主机记录和财务记录。 第二个探险者不能以相同名称启动,因此Codex在其主线程中运行了只读的调查。
  • 往返工作的代理写下的一个125行的ConversionJob中,有依赖注入,测试2的2也通过,亦适用于一个全新的克隆。
  • 提示16在out/api-probe/中留下40个文件,但SheetConvert仍然构建。
  • Codex的沙箱无法访问nuget.org,因此恢复使用了本地包缓存。 所有16个Release构建成功。 初次全程运行失败。 它的循环中复制了源单元格到重建表,字节检查也增加了密码步骤,其重构在out/converted/中留有未更新文件,API探查在工程内放置第二个程序,破坏了构建。 在此运行报告之前紧密处理了提示9、11、14和16。

Codex的版本、模型、计时和此运行的测试机器在共享的运行记录中。


故障排除


有问题吗?

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

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

阅读更多

准备开始了吗?

NuGet 下载量 2,393,101版本:2026.11刚刚发布