— – Created by: Takaaki Naganoya – Created on: 2019/07/21 — – Copyright © 2019 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" — Yosemite (10.10) or later use framework "Foundation" use scripting additions
property NSString : a reference to current application’s NSString property NSArray : a reference to current application’s NSArray property NSRegularExpressionSearch : a reference to current application’s NSRegularExpressionSearch
repeat with i from 1 to 1351 set a to numAdrToColumnEncode(i) of me set b to colAddrToNumDecode(a) of me set aRes to (i = b) as boolean log {i, b, a, aRes} if aRes = false then display dialog i as string end repeat
–10進数数値をExcel 2004/2008的カラム表現にエンコードするサブルーチン(エンコード範囲:1〜1351) on numAdrToColumnEncode(origNum) if origNum > 1351 then error "エラー:Numbersのカラム表現(A1形式)への変換ルーチンにおいて、想定範囲外(1351以上)のパラメータが指定されました" end if set upperDigitEncTable to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A"} set lowerDigitEncTable to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "A"} set oNum to origNum set nTh to 26 set stringLength to 4 –数字が1桁の場合の対応 if origNum < 27 then set aRes to (item origNum of upperDigitEncTable) as string return aRes end if if origNum > 702 then –3桁になる場合 set upupNum to oNum div 676 –整数除算–上の上の桁 set oNum to oNum – (upupNum * 676) set upNum to oNum div 26 –整数除算–上の桁 set lowNum to oNum mod 26 – 1 –余剰計算–下の桁 –log {origNum, upupNum, upNum, lowNum} –超つじつま合わせルーチン【強引】 if lowNum = -1 then set upNum to upNum – 1 set lowNum to 25 end if set upupChar to (item upupNum of upperDigitEncTable) as string set upChar to (item upNum of upperDigitEncTable) as string set lowChar to (item (lowNum + 1) of lowerDigitEncTable) as string set resText to upupChar & upChar & lowChar else –2桁の場合 set upNum to oNum div 26 –整数除算–上の桁 set lowNum to oNum mod 26 – 1 –余剰計算–下の桁 –超つじつま合わせルーチン【強引】 if lowNum = -1 then set upNum to upNum – 1 set lowNum to 25 end if set upChar to (item upNum of upperDigitEncTable) as string set lowChar to (item (lowNum + 1) of lowerDigitEncTable) as string set resText to upChar & lowChar end if return resText end numAdrToColumnEncode
–Numbersの横方向アドレス(A〜Zの26進数)文字列を10進数に変換 on colAddrToNumDecode(origStr) return aNthToDecimal(origStr, {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}) of me end colAddrToNumDecode
–n進数文字列を10進数に変換する on aNthToDecimal(origStr, nTh) set resNumber to 0 set sList to reverse of (characters of origStr) set aLen to length of nTh set digitCount to 0 repeat with i in sList set j to contents of i set aRes to offsetInList(j, nTh) of me set resNumber to resNumber + (aLen ^ digitCount) * aRes set digitCount to digitCount + 1 end repeat return resNumber as integer end aNthToDecimal
on offsetInList(aChar, aList) set anArray to NSArray’s arrayWithArray:aList set aInd to (anArray’s indexOfObject:aChar) if aInd = current application’s NSNotFound or (aInd as number) > 9.99999999E+8 then error "Invalid Character Error" else return (aInd as integer) + 1 –0 to 1 based index conversion end if end offsetInList
|