feat: sync latest ARR implementation

This commit is contained in:
Wyndham ARR
2026-07-31 15:11:42 +08:00
parent d6f8a747fa
commit bf7939dd1a
185 changed files with 17527 additions and 2260 deletions

View File

@@ -242,6 +242,11 @@ function writeSheet(workbook, channel) {
const lastRow = matrix.length;
const used = sheet.getRange(`A1:${lastColumn}${lastRow}`);
used.values = matrix;
if (channel.rows.length > 0) {
sheet.getRange(`S2:S${lastRow}`).formulas = channel.rows.map((_, index) => [
`=R${index + 2}*C${index + 2}*G${index + 2}`,
]);
}
used.format.font = { name: "Arial", size: 10, color: BODY_FONT };
used.format.verticalAlignment = "center";
used.format.borders = {
@@ -328,22 +333,41 @@ async function validateWorkbook(workbook, payload, stage) {
}
});
});
const formulas = used?.formulas ?? [];
formulas.forEach((formulaRow, rowIndex) => {
formulaRow.forEach((formulaValue, columnIndex) => {
const formula = String(formulaValue ?? "").trim();
if (!formula) return;
formulaCount += 1;
const expectedFormula = `=R${rowIndex + 1}*C${rowIndex + 1}*G${rowIndex + 1}`;
if (
rowIndex < 1
|| columnIndex !== channel.headers.indexOf("TOTAL PRICE")
|| formula !== expectedFormula
) {
fail(`${stage} workbook contains an unauthorized formula`);
}
});
});
const inspected = await workbook.inspect({
kind: "formula",
sheetId: channel.worksheet,
range: `A1:${lastColumn}${expectedRows}`,
maxChars: 6000,
options: { maxResults: 100 },
options: { maxResults: Math.max(channel.rows.length + 10, 100) },
});
const inspectionText = String(inspected.ndjson ?? "");
formulaCount += inspectionText
.split("\n")
.filter((line) => line.includes('"kind":"formula"')).length;
if (/#REF!|#DIV\/0!|#VALUE!|#NAME\?|#N\/A/.test(inspectionText)) {
fail(`${stage} workbook contains a formula error`);
}
}
if (formulaCount !== 0) fail(`${stage} workbook must contain no formulas`);
const expectedFormulaCount = payload.channels.reduce(
(total, channel) => total + channel.rows.length,
0,
);
if (formulaCount !== expectedFormulaCount) {
fail(`${stage} workbook TOTAL PRICE formulas are incomplete`);
}
return formulaCount;
}