:xspreadsheet的坐標轉數組下標
xspreadsheet坐標是像這樣的:A1,第A列第1行,對應到數組,列下標0,行下標0。

行轉數組下標直接減1就行,列則需要按字母順序替換為數字0到25(即 'A' 替換為 '0','B' 替換為 '1',以此類推)。
轉換JS:
function replaceUpToNum(str) {
let result = '';
for (let i = 0; i < str.length; i++) {
const charCode = str.charCodeAt(i);
if (charCode >= 65 && charCode <= 90) {
const number = charCode - 65;
result += number.toString();
} else {
result += str[i];
}
}
return result;
}
const inputString = "HELLO WORLD";
const outputString = replaceUpToNum(inputString);
console.log(outputString);
該文章在 2024/6/27 16:08:08 編輯過