Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(office): preserve cross-sheet formulas during workbook creation
CloudTianTian8f0a2cf85f89
diff --git a/scripts/run-office-artifact-smoke.mjs b/scripts/run-office-artifact-smoke.mjsindex 44171eec..97ae7652 100644--- a/scripts/run-office-artifact-smoke.mjs+++ b/scripts/run-office-artifact-smoke.mjs@@ -219,8 +219,10 @@ try {sheets: [{name: '汇总',+ columns: [{ name: 'A', width: '24' }, { name: 'B', width: '18' }],rows: [- [{ value: '合计', bold: true }, { formula: 'SUM(数据!B2:B2)', format: '0.00' }],+ [{ value: '合计', bold: true }, { formula: "SUM('数据'!$B$2:$B$2)", format: '0.00' }],+ [7],],charts: [{type: 'column',@@ -238,6 +240,11 @@ try {},{name: '数据',+ columns: [+ { name: 'A', width: '24' },+ { name: 'B', width: '18' },+ { name: 'C', width: '16' },+ ],rows: [[{ value: '客户编号', bold: true },@@ -246,6 +253,8 @@ try {[{ value: '00123', format: '@' },{ value: 100, format: '0.00' },+ { formula: "'汇总'!$A$2" },+ { formula: '汇总!A2' },],],},@@ -255,6 +264,22 @@ try {assert(!createXlsxResult.isError, `create_xlsx with native chart failed: ${createXlsxResult.content}`);assert(produced.has(workbook), 'create_xlsx did not register the charted workbook');+ // Reopen the real saved workbook: layout changes must preserve the requested+ // formula addresses and their independently known values in both directions.+ for (const [target, formula, value] of [+ ['/汇总/B1', "SUM('数据'!$B$2:$B$2)", '100'],+ ['/数据/C2', "'汇总'!$A$2", '7'],+ ['/数据/D2', '汇总!A2', '7'],+ ]) {+ const result = await officeRead.execute({+ path: workbook, mode: 'get', targets: [target],+ }, { workingDir: tempDir, state: {} });+ assert(!result.isError, `created XLSX formula read failed: ${result.content}`);+ const match = firstOfficeReadMatch(result, 'created XLSX cross-sheet formula');+ assert(match.format?.formula === formula, `created XLSX formula changed: ${JSON.stringify(match.format?.formula)}`);+ assert(Number(match.text) === Number(value), `created XLSX formula value was ${JSON.stringify(match.text)}, expected ${value}`);+ }+const chart = commandText(run(binary, ['get', workbook, '/汇总/chart[1]', '--json']));assertContains(chart, '"chartType": "column"', 'native workbook chart');assertContains(chart, '"title": "客户金额"', 'native workbook chart title');@@ -363,7 +388,7 @@ try {);}- console.log(`[office-artifact-smoke] PASS ${platformKey} OfficeCLI=${version} artifacts=3 production-fixtures=${fixtureScenarios.length} native-xlsx-chart=true xlsx-edit-readback=true tool-copy=true source-preserved=true atomic-rollback=true guarded-html-renders=3`);+ console.log(`[office-artifact-smoke] PASS ${platformKey} OfficeCLI=${version} artifacts=3 production-fixtures=${fixtureScenarios.length} native-xlsx-chart=true xlsx-cross-sheet-layout=true xlsx-edit-readback=true tool-copy=true source-preserved=true atomic-rollback=true guarded-html-renders=3`);} catch (error) {failed = true;console.error(`[office-artifact-smoke] FAIL: ${error instanceof Error ? error.message : String(error)}`);diff --git a/src/main/model/core-agent/office-batch.ts b/src/main/model/core-agent/office-batch.tsindex 55943fa9..c5e9dc41 100644--- a/src/main/model/core-agent/office-batch.ts+++ b/src/main/model/core-agent/office-batch.ts@@ -299,9 +299,10 @@ export type XlsxSheetSpec = {* Build the `batch` ops for a multi-sheet workbook. A freshly created xlsx has* exactly one sheet, `Sheet1`; the first spec reuses it (renamed via `set` when* its `name` differs), and each later spec is `add`ed. This is deliberately- * three-pass: create every sheet first so dashboard formulas may reference- * later sheets, populate every sheet next, then add charts after all referenced- * source cells exist.+ * four-pass: create every sheet, establish every column layout, populate cells,+ * then add charts after their source cells exist. OfficeCLI's column additions+ * shift existing quoted cross-sheet references, even when used for widths, so+ * no sheet's layout may be added after another sheet's formulas are written.*/export function buildXlsxWorkbookBatch(sheets: readonly XlsxSheetSpec[]): OfficeBatchOp[] {const ops: OfficeBatchOp[] = [];@@ -326,6 +327,8 @@ export function buildXlsxWorkbookBatch(sheets: readonly XlsxSheetSpec[]): Officeops.push({ command: 'add', parent: `/${name}`, type: 'column', props: colProps });}}+ }+ for (const { sheet, name } of normalized) {if (Array.isArray(sheet.rows)) ops.push(...buildXlsxBatch(name, sheet.rows));}for (const { sheet, name } of normalized) {diff --git a/test/main/model/core-agent/office-batch.test.ts b/test/main/model/core-agent/office-batch.test.tsindex 670432b1..839f86cb 100644--- a/test/main/model/core-agent/office-batch.test.ts+++ b/test/main/model/core-agent/office-batch.test.ts@@ -87,7 +87,7 @@ describe('buildXlsxWorkbookBatch', () => {]);});- it('creates all sheets before cross-sheet formulas and all cells before charts', () => {+ it('creates all sheets and column layouts before cross-sheet formulas, then charts', () => {const ops = buildXlsxWorkbookBatch([{name: '看板',@@ -100,6 +100,7 @@ describe('buildXlsxWorkbookBatch', () => {},{name: '数据',+ columns: [{ name: 'A', width: 24 }, { name: 'B', width: 16 }],rows: [['日期', '销售额'], ['7月1日', 100], ['7月2日', 120]],},]);@@ -108,6 +109,11 @@ describe('buildXlsxWorkbookBatch', () => {const finalDataCell = ops.findIndex((op) => 'path' in op && op.path === '/数据/B3');const chart = ops.findIndex((op) => 'type' in op && op.type === 'chart');expect(addDataSheet).toBeLessThan(dashboardFormula);+ // Engine column additions rewrite existing cross-sheet references. Width+ // settings must therefore precede formulas on every sheet, not just this one.+ for (const [index, op] of ops.entries()) {+ if ('type' in op && op.type === 'column') expect(index).toBeLessThan(dashboardFormula);+ }expect(dashboardFormula).toBeLessThan(finalDataCell);expect(finalDataCell).toBeLessThan(chart);});