automating-excel
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAutomating Excel (JXA-first, AppleScript discovery)
在macOS上自动化Excel(优先使用JXA,结合AppleScript探索)
Relationship to the macOS automation skill
与macOS自动化技能的关系
- Standalone for Excel, but aligned with patterns.
automating-mac-apps - Use for permissions, shell, and UI scripting guidance.
automating-mac-apps - PyXA Installation: To use PyXA examples in this skill, see the installation instructions in skill (PyXA Installation section).
automating-mac-apps
- 是针对Excel的独立技能,但与的模式保持一致。
automating-mac-apps - 如需权限、Shell和UI脚本相关指导,请参考技能。
automating-mac-apps - PyXA安装:若要使用本技能中的PyXA示例,请查看技能中的安装说明(PyXA安装章节)。
automating-mac-apps
Core Framing
核心框架
- Excel AppleScript dictionary is AppleScript-first; use Script Editor for discovery.
- JXA is the production language for logic and data processing.
- Collections are specifiers; read via methods, set via assignments.
- Handle errors from Excel operations using try/catch blocks and Application error checking.
- Excel的AppleScript字典以AppleScript为优先;可使用Script Editor进行探索。
- JXA是用于逻辑和数据处理的生产级语言。
- 集合是指定符;通过方法读取,通过赋值设置。
- 使用try/catch块和应用程序错误检查来处理Excel操作中的错误。
Workflow (default)
工作流(默认)
- Discover dictionary terms in Script Editor (Excel).
- Prototype a minimal AppleScript command.
- Port to JXA and add defensive checks.
- Use bulk read/write (2D arrays) for performance.
- Use VBA when dictionary coverage is missing.
run()
- 在Script Editor(Excel)中探索字典术语。
- 编写最小化的AppleScript命令原型。
- 移植到JXA并添加防御性检查。
- 使用批量读/写(二维数组)提升性能。
- 当字典未覆盖相关功能时,使用VBA的方法。
run()
Validation Steps
验证步骤
- Test with empty documents to verify error handling
- Verify data integrity after batch operations
- Check Excel UI responsiveness after automation runs
- Log errors with specific Excel object paths for debugging
- 使用空文档测试以验证错误处理能力
- 批量操作后验证数据完整性
- 自动化运行后检查Excel UI的响应性
- 记录包含具体Excel对象路径的错误信息以用于调试
Examples
示例
Basic workbook read:
javascript
const Excel = Application('Microsoft Excel');
const workbook = Excel.workbooks[0];
const worksheet = workbook.worksheets['Sheet1'];
const range = worksheet.ranges['A1:B10'];
const data = range.value(); // Returns 2D arrayBulk write with performance toggle:
javascript
Excel.screenUpdating = false;
Excel.calculation = 'manual';
try {
const range = worksheet.ranges['C1:D100'];
range.value = my2DArray;
} finally {
Excel.calculate();
Excel.screenUpdating = true;
}VBA escape hatch:
javascript
Excel.run('MyMacro', {arg1: 'value', arg2: 123}); // Calls VBA subroutine基础工作簿读取:
javascript
const Excel = Application('Microsoft Excel');
const workbook = Excel.workbooks[0];
const worksheet = workbook.worksheets['Sheet1'];
const range = worksheet.ranges['A1:B10'];
const data = range.value(); // Returns 2D array带性能开关的批量写入:
javascript
Excel.screenUpdating = false;
Excel.calculation = 'manual';
try {
const range = worksheet.ranges['C1:D100'];
range.value = my2DArray;
} finally {
Excel.calculate();
Excel.screenUpdating = true;
}VBA应急方案:
javascript
Excel.run('MyMacro', {arg1: 'value', arg2: 123}); // Calls VBA subroutineWhen Not to Use
不适用场景
- For general macOS automation without Excel involvement
- When AppleScript alone suffices (no JXA logic needed)
- For Excel tasks requiring complex UI interactions (use for that)
automating-mac-apps - When cross-platform compatibility is required
- 无需涉及Excel的通用macOS自动化场景
- 仅使用AppleScript即可满足需求的场景(无需JXA逻辑)
- 需要复杂UI交互的Excel任务(此类场景请使用技能)
automating-mac-apps - 需要跨平台兼容性的场景
What to load
需加载的资源
- JXA Excel basics:
automating-excel/references/excel-basics.md - Recipes (ranges, 2D arrays, formatting):
automating-excel/references/excel-recipes.md - Advanced patterns (performance toggles, VBA bridge):
automating-excel/references/excel-advanced.md - Pivot table guidance:
automating-excel/references/excel-pivots.md - Charting guidance:
automating-excel/references/excel-charts.md - Dictionary translation table:
automating-excel/references/excel-dictionary.md - PyXA (Python) alternative:
automating-excel/references/excel-pyxa.md
- JXA Excel基础:
automating-excel/references/excel-basics.md - 操作指南(单元格区域、二维数组、格式设置):
automating-excel/references/excel-recipes.md - 高级模式(性能开关、VBA桥接):
automating-excel/references/excel-advanced.md - 数据透视表指南:
automating-excel/references/excel-pivots.md - 图表指南:
automating-excel/references/excel-charts.md - 字典转换表:
automating-excel/references/excel-dictionary.md - PyXA(Python)替代方案:
automating-excel/references/excel-pyxa.md