MCPcopy Index your code
hub / github.com/simstudioai/sim / recalcXlsx

Function recalcXlsx

apps/sim/lib/copilot/tools/server/files/doc-recalc.ts:32–76  ·  view source on GitHub ↗
(args: {
  binary: Buffer
  workspaceId: string
})

Source from the content-addressed store, hash-verified

30 * sandbox/infra failure.
31 */
32export async function recalcXlsx(args: {
33 binary: Buffer
34 workspaceId: string
35}): Promise<XlsxRecalcResult> {
36 const script = `
37import json, openpyxl
38
39ERR = {"#REF!", "#DIV/0!", "#VALUE!", "#NAME?", "#N/A", "#NULL!", "#NUM!"}
40
41# Input is already recalculated by compileDoc, so cached values are present.
42wb = openpyxl.load_workbook("/home/user/input.xlsx", data_only=True)
43errors = []
44for ws in wb.worksheets:
45 for row in ws.iter_rows():
46 for c in row:
47 if isinstance(c.value, str) and c.value.strip() in ERR:
48 errors.append({"sheet": ws.title, "cell": c.coordinate, "error": c.value.strip()})
49
50print("__SIM_RESULT__=" + json.dumps({"ok": len(errors) == 0, "errors": errors[:${MAX_REPORTED_ERRORS}]}))
51`.trim()
52
53 const result = await executeInE2B({
54 code: script,
55 language: CodeLanguage.Python,
56 timeoutMs: RECALC_TIMEOUT_MS,
57 sandboxKind: 'doc',
58 sandboxFiles: [
59 {
60 path: '/home/user/input.xlsx',
61 content: args.binary.toString('base64'),
62 encoding: 'base64',
63 },
64 ],
65 })
66
67 if (result.error) {
68 throw new Error(`Spreadsheet recalc failed: ${result.error}`)
69 }
70 const payload = result.result as XlsxRecalcResult | null
71 if (!payload || typeof payload.ok !== 'boolean') {
72 logger.warn('Recalc returned no structured result', { workspaceId: args.workspaceId })
73 return { ok: true, errors: [] }
74 }
75 return { ok: payload.ok, errors: Array.isArray(payload.errors) ? payload.errors : [] }
76}
77
78/** Single-line summary of the first few formula errors, for the compiled-check result. */
79export function formatXlsxErrors(errors: XlsxCellError[]): string {

Callers 1

runE2BCompiledCheckFunction · 0.85

Calls 3

executeInE2BFunction · 0.90
warnMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected