chore: snapshot production code before Apple Design UI refinement
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { FileBlob, SpreadsheetFile } from "@oai/artifact-tool";
|
||||
|
||||
const inputPath = "/Users/lingniu/Documents/里程异常统计表_20251128-20260731-回复.xlsx";
|
||||
const outputDir = "/Users/lingniu/project/ai-coding/lingniu-vehicle-ingest/tmp/mileage-appeal-20260810/source-preview";
|
||||
await fs.mkdir(outputDir, { recursive: true });
|
||||
|
||||
const input = await FileBlob.load(inputPath);
|
||||
const workbook = await SpreadsheetFile.importXlsx(input);
|
||||
|
||||
const overview = await workbook.inspect({
|
||||
kind: "workbook,sheet,table,drawing",
|
||||
maxChars: 20000,
|
||||
tableMaxRows: 12,
|
||||
tableMaxCols: 20,
|
||||
tableMaxCellChars: 180,
|
||||
});
|
||||
await fs.writeFile(path.join(outputDir, "overview.ndjson"), overview.ndjson, "utf8");
|
||||
|
||||
const sheets = [];
|
||||
for (let i = 0; ; i += 1) {
|
||||
let sheet;
|
||||
try {
|
||||
sheet = workbook.worksheets.getItemAt(i);
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
if (!sheet) break;
|
||||
const name = sheet.name;
|
||||
const used = sheet.getUsedRange();
|
||||
const usedAddress = used?.address ?? null;
|
||||
const info = await workbook.inspect({
|
||||
kind: "region,computedStyle,formula",
|
||||
sheetId: name,
|
||||
range: usedAddress ?? "A1:Z60",
|
||||
maxChars: 30000,
|
||||
tableMaxRows: 80,
|
||||
tableMaxCols: 30,
|
||||
tableMaxCellChars: 240,
|
||||
options: { maxResults: 200 },
|
||||
});
|
||||
await fs.writeFile(path.join(outputDir, `${String(i + 1).padStart(2, "0")}-${name.replaceAll(/[\\/:*?\[\]]/g, "_")}.ndjson`), info.ndjson, "utf8");
|
||||
const preview = await workbook.render({ sheetName: name, autoCrop: "all", scale: 1, format: "png" });
|
||||
const previewPath = path.join(outputDir, `${String(i + 1).padStart(2, "0")}-${name.replaceAll(/[\\/:*?\[\]]/g, "_")}.png`);
|
||||
await fs.writeFile(previewPath, new Uint8Array(await preview.arrayBuffer()));
|
||||
sheets.push({ index: i, name, usedAddress, previewPath });
|
||||
}
|
||||
|
||||
await fs.writeFile(path.join(outputDir, "sheets.json"), JSON.stringify(sheets, null, 2), "utf8");
|
||||
console.log(JSON.stringify(sheets, null, 2));
|
||||
Reference in New Issue
Block a user