跳至內容
Astera Technology

試算表名稱為何匯入成數字 1?

共用字串索引要對回所附字串表,不直接當名稱。

下載完整個案資料及參考答案 ↓

先核來源與已訂規則

本例共用字串格是 [Ada,Bo] 的索引 1,索引由零起,所以文字是 Bo。匯入約定只收表內整數位置;例子處理已抽記錄,並不解析 XLSX 檔案包。

已填假設輸入
紀錄輸入 JSON
原例輸入{"index":1,"shared":["Ada","Bo"]}
下載可編輯 CSV ↓

比較兩條實際路徑

錯路把參考位置當文字 1,更正才是 Bo。若缺共用表,就沒有足夠資料還原名稱。

錯誤與更正路徑的輸出
路徑輸出 JSON
錯誤路徑{"accepted":true,"text":"1"}
更正路徑{"accepted":true,"text":"Bo"}
下載可編輯 CSV ↓
本地 Node.js 程序:22.23.3 或 24.14.1
import {DatabaseSync} from 'node:sqlite';
import {TextDecoder} from 'node:util';
import {inflateSync} from 'node:zlib';
import {posix} from 'node:path';
import {createHash} from 'node:crypto';
const rows=(db,sql)=>db.prepare(sql).all().map(r=>({...r}));
const failed=(action)=>{try{action();return null;}catch(e){return {code:e.errcode??e.code??e.name};}};

import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
    if(!corrected)return {accepted:true,text:String(i.index)};
    if(!Number.isInteger(i.index)||i.index<0||i.index>=i.shared.length)return {accepted:false,error:'shared-string-reference'};
    return {accepted:true,text:i.shared[i.index]};
  };
const cases=[{"label":"misleading base","input":{"index":1,"shared":["Ada","Bo"]},"expected":{"accepted":true,"text":"1"},"corrected":false},{"label":"corrected base","input":{"index":1,"shared":["Ada","Bo"]},"expected":{"accepted":true,"text":"Bo"},"corrected":true},{"label":"first shared string","input":{"index":0,"shared":["Ada","Bo"]},"expected":{"accepted":true,"text":"Ada"},"corrected":true},{"label":"out of bounds reference","input":{"index":2,"shared":["Ada","Bo"]},"expected":{"accepted":false,"error":"shared-string-reference"},"corrected":true}];
for(const test of cases){
  const actual=run(test.input,test.corrected);
  assert.deepEqual(actual,test.expected,test.label);
  console.log(test.label,actual);
}
下載可執行例子 ↓

下次載入前核邊界

索引零得 Ada;兩項表沒有索引二,要暫停。

可編輯邊界紀錄及預期輸出
情況輸入 JSON預期輸出 JSON
首個共用字串位置{"index":0,"shared":["Ada","Bo"]}{"accepted":true,"text":"Ada"}
索引超出字串表{"index":2,"shared":["Ada","Bo"]}{"accepted":false,"error":"shared-string-reference"}
下載可編輯 CSV ↓

此處索引 1 對哪個文字?

查看參考答案

Bo,1 是共用字串表位置,不是名稱。

相關資源