Numbersの最前面の書類の選択中のシート(アクティブシート)上の「表」の行数をデータに合わせて変更するAppleScriptです。
▲Before
▲After
表データ上の空白部分を末尾(下)から先頭(上)に向かってサーチし、空白ではない箇所を見つけるまで繰り返します。
AppleScript名:Numbersのアクティブシート上の表の行数をデータに合わせる |
— Created 2018-06-12 by Takaaki Naganoya — 2018 Piyomaru Software use AppleScript version "2.5" use scripting additions use framework "Foundation" use bPlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html set tCount to getTableCount() of me repeat with tableID from 1 to tCount –Numbersからデータを取得する set aList to getDataFromNumbersDoc(tableID) of me if aList = false then error "No Data in table " & (tableID as string) –Numbersの対象の表の情報を取得 set aWidth to getColumnCount(tableID) of me set aHeaderCount to getHeaderCount(tableID) of me set aFooterCount to getFooterCount(tableID) of me –Numbersから取得した2D Listのデータからデータの末尾を見つける set aDataRowCount to findDataEnd(aWidth, aHeaderCount, aFooterCount, aList) of me tell application "Numbers" tell front document tell active sheet tell table tableID set row count to aDataRowCount end tell end tell end tell end tell end repeat –Numbersでオープン中の書類の選択中のシートの表1からデータを取得して2D Listに on getDataFromNumbersDoc(tableNum as integer) load framework tell application "Numbers" if (count every document) = 0 then return false tell front document if (count every sheet) = 0 then return false tell active sheet tell table tableNum set colCount to column count set rowCount to row count set headerCount to header row count set footerCount to footer row count set dList to value of every cell of cell range end tell end tell end tell end tell –Convert 1D List to 2D List set bList to (current application’s SMSForder’s subarraysFrom:dList groupedBy:colCount |error|:(missing value)) as list set sItem to 1 + headerCount set eItem to rowCount – footerCount set cList to items sItem thru eItem of bList return cList end getDataFromNumbersDoc on getTableCount() tell application "Numbers" set dCount to count every document if dCount = 0 then error "Numbers: There is No Document" tell front document tell active sheet return (count every table) end tell end tell end tell end getTableCount on getHeaderCount(tableID as integer) tell application "Numbers" tell front document tell active sheet tell table tableID return (header row count) end tell end tell end tell end tell end getHeaderCount on getFooterCount(tableID as integer) tell application "Numbers" tell front document tell active sheet tell table tableID return (footer row count) end tell end tell end tell end tell end getFooterCount on getColumnCount(tableID as integer) tell application "Numbers" tell front document tell active sheet tell table tableID return (column count) end tell end tell end tell end tell end getColumnCount –Numbersから取得した2D Arrayのデータ末尾を見つける(ただし、高速化処理を一切していないのでデータ数が数千件を超えると遅くなる) on findDataEnd(aWidth as integer, aHeaderCount as integer, aFooterCount as integer, aList as list) set rAList to reverse of aList –get reverse order list set anItem to {} repeat aWidth times set the end of anItem to missing value end repeat set aCount to length of aList set hitF to false repeat with i in rAList set j to contents of i if j is not equal to anItem then set hitF to true exit repeat end if set aCount to aCount – 1 end repeat if hitF = false then return false –すべて空(missing value)だった場合には処理打ち切り return aCount + aHeaderCount + aFooterCount end findDataEnd |
More from my site
(Visited 159 times, 1 visits today)