AppleScript Microsoft Excel

[Excel]祭日入りカレンダー生成

Screencapture-20230610-130744

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

####設定項目
set numFontSize to 14 as number
##set strFontName to "Osaka−等幅" as text
##set strFontName to "Arial Unicode MS" as text
set strFontName to "メイリオ" as text


########################
#####ここから処理
####日付情報の取得--> 今の『年』の数値を求める
set ocidDate to refMe's NSDate's |date|()
set ocidCalendar to refMe's NSCalendar's autoupdatingCurrentCalendar()
set ocidCalendarUnitYear to refMe's NSCalendarUnitYear
set ocidCalendarUnitMonth to refMe's NSCalendarUnitMonth
set ocidDateComponents to ocidCalendar's components:((ocidCalendarUnitYear) + (ocidCalendarUnitMonth)) fromDate:ocidDate
set numSetYear to (ocidDateComponents's |year|) as integer
set numSetMonth to (ocidDateComponents's |month|) as integer
#####各種リスト
set listWeekDay to {"日", "月", "火", "水", "木", "金", "土"} as list
set listYear to {(numSetYear - 1), (numSetYear), (numSetYear + 1)} as list
set listMonth to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} as list
########################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
#####年ダイアログを出す
try
  set objResponseYear to (choose from list listYear with title "年選択" with prompt "年を選択してください" default items (item 2 of listYear) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
  log "エラーしました"
return
end try
if objResponseYear is false then
return
end if
set numSetYear to (objResponseYear) as integer
########################
#####月ダイアログを出す
if numSetMonth = 12 then
  set numSetMonth to 1 as integer
else
  set numSetMonth to numSetMonth + 1 as integer
end if
try
  set objResponseMonth to (choose from list listMonth with title "月選択" with prompt "月を選択してください" default items (item (numSetMonth) of listMonth) OK button name "OK" cancel button name "キャンセル" with multiple selections allowed without empty selection allowed)
on error
  log "エラーしました"
return
end try
if objResponseMonth is false then
return
end if
set numSetMonth to (objResponseMonth) as integer



########################
tell application "Microsoft Excel" to launch
###エクセルの基本処理
set strMonthNoZeroSupp to (text -2 through -1 of ("00" & numSetMonth)) as text
set strSheetName to ("" & numSetYear & "-" & strMonthNoZeroSupp & "") as text
set strFileName to ("" & strSheetName & "カレンダーxlsx") as text
set strDesktopPath to POSIX path of (path to desktop folder from user domain) as text
set strSaveFilePath to (strDesktopPath & strFileName) as text
####新規ワークブック
tell application "Microsoft Excel"
  activate
  set objWorkBook to make new workbook with properties {excel 8 compatibility mode:false}
  tell objWorkBook
    set strWorkBookName to name as text
  end tell
end tell
####シートの名前の変更
tell application "Microsoft Excel"
  tell objWorkBook
    tell active sheet
      set name to strSheetName
    end tell
  end tell
end tell
###A1 左上のセルの処理
tell application "Microsoft Excel"
  tell objWorkBook
    tell sheet strSheetName
      tell cell "A1"
set number format to "@"
###Aに年月を入力
set value to ("" & (numSetYear as text) & "/" & strMonthNoZeroSupp) as text
####タイトル行の処理
tell cell "$1:$1"
tell font object
set font size to numFontSize
set name to strFontName
set color to {0, 0, 0}
end tell
tell interior object
set color to {255, 255, 255}
end tell
tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
end tell
end tell
      end tell
    end tell
  end tell
end tell
########################
#####カレンダー初期化
set ocidCalendar to refMe's NSCalendar's calendarWithIdentifier:(refMe's NSCalendarIdentifierGregorian)
set ocidLocale to refMe's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP")
ocidCalendar's setLocale:(ocidLocale)
#####日付コンポーネント初期化
set ocidDateComponents to refMe's NSDateComponents's alloc()'s init()
ocidDateComponents's setYear:(numSetYear)
ocidDateComponents's setMonth:(numSetMonth)
set ocidDate to ocidCalendar's dateFromComponents:(ocidDateComponents)
###指定月のカレンダーの最大日数-->繰り返し回数になる
set ocidMonthDateRange to ocidCalendar's rangeOfUnit:(refMe's NSCalendarUnitDay) inUnit:(refMe's NSCalendarUnitMonth) forDate:(ocidDate)
set numDateLength to ocidMonthDateRange's |length|


########################
###祭日データJSONで取得
set strURL to "https://holidays-jp.github.io/api/v1/date.json" as text
set ocidJsonURL to refMe's NSURL's URLWithString:(strURL)
set ocidOption to refMe's NSDataReadingMappedIfSafe
set listDownLoadData to refMe's NSData's dataWithContentsOfURL:(ocidJsonURL) options:(ocidOption) |error|:(reference)
set ocidJsonData to (item 1 of listDownLoadData)
#####################
###JSON初期化 してレコードに格納
set listJSONSerialization to (refMe's NSJSONSerialization's JSONObjectWithData:(ocidJsonData) options:0 |error|:(reference))
set ocidJsonData to item 1 of listJSONSerialization
set ocidHolidayDict to refMe's NSDictionary's alloc()'s initWithDictionary:(ocidJsonData)

#####################
###取得するカレンダーの月(処理としては不要なんだけど、今後の展開のために処理)
set numYear to ocidCalendar's component:(refMe's NSCalendarUnitYear) fromDate:(ocidDate)
set numMonth to ocidCalendar's component:(refMe's NSCalendarUnitMonth) fromDate:(ocidDate)
###年はそのまま
set strYear to numYear as text
###月はゼロサプレス
set strMonth to (text -2 through -1 of ("00" & (numMonth as text))) as text
###日付毎処理
set numCntRows to 2

repeat with numDayNo from (1) to (numDateLength)
  -->ここまでは年と月でのカレンダーなので
  ###日付を入れて
(ocidDateComponents's setDay:(numDayNo))
  set ocidDate to (ocidCalendar's dateFromComponents:(ocidDateComponents))
  set ocidWeekDayClender to (ocidCalendar's components:(refMe's NSWeekdayCalendarUnit) fromDate:(ocidDate))
  ###日付
  log ocidDate as date
  ###日付番号
  log numDayNo
  set strDayNoZeroSupp to (text -2 through -1 of ("00" & numDayNo)) as text
  #####################
  ###曜日処理
  set numWeekDayNo to (ocidWeekDayClender's |weekday|)'s intValue()
  ###曜日番号
  log numWeekDayNo
  ###曜日テキスト
  set strWeekDayJp to (item numWeekDayNo of listWeekDay) as text
  ###祭日取得用
  set strDateText to ("" & strYear & "-" & strMonth & "-" & strDayNoZeroSupp & "") as text
  ###祭日取得
  set ocidHolidayValue to (ocidHolidayDict's valueForKey:(strDateText))
  ###祭日処理
  if ocidHolidayValue is (missing value) then
    set numChkHoliday to 0 as integer
  else
    set numChkHoliday to 1 as integer
    set strHolidayValue to ocidHolidayValue as text
    log strHolidayValue
    ####Cの列
    set strCellNoHoliday to ("C" & numCntRows & "") as text
    tell application "Microsoft Excel"
      tell objWorkBook
tell sheet strSheetName
tell cell strCellNoHoliday
###Cの列に祭日名を入力
set value to (strHolidayValue)
end tell
end tell
      end tell
    end tell
  end if
  
  ###セル番号
  set strCellNoDay to ("A" & numCntRows & "") as text
  set strCellNoWeek to ("B" & numCntRows & "") as text
  set strCellRowsRange to "$" & numCntRows & ":$" & numCntRows & ""
  
  ########################
  ###エクセル処理
  tell application "Microsoft Excel"
    tell objWorkBook
      tell sheet strSheetName
tell cell strCellNoWeek
set value to strWeekDayJp
end tell
tell cell strCellNoDay
set value to strDayNoZeroSupp
end tell
      end tell
    end tell
    #######行処理
    tell cell strCellRowsRange
      set number format to "@"
      #####
      tell interior object
if numWeekDayNo = 1 then
set color to {254, 188, 190}
else if numWeekDayNo = 7 then
set color to {212, 243, 255}
else if numChkHoliday = 1 then
set color to {254, 188, 190}
else
set color to {255, 255, 255}
end if
      end tell
      #####
      tell font object
set font size to numFontSize
set name to strFontName
if numWeekDayNo = 1 then
set color to {170, 0, 0}
else if numWeekDayNo = 7 then
set color to {0, 88, 176}
else if numChkHoliday = 1 then
set color to {170, 0, 0}
else
set color to {0, 0, 0}
end if
      end tell
      tell border id border top
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border bottom
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border left
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
      tell border id border right
set color to {0, 0, 0}
#set color index to color index automatic
set line style to continuous
set weight to border weight thin
#set tint and shade to 0.0
      end tell
    end tell
  end tell
  
  set numCntRows to numCntRows + 1
end repeat

|

[Excel]行番号を入れる(ゼロサプレス)

Screencapture-20230519-131838

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

set strZeroSup to "000" as text

set numMaxRow to 200 as integer

###起動
tell application "Microsoft Excel"
  launch
end tell
####起動待ち最大20秒
repeat 20 times
  tell application "Microsoft Excel"
    activate
    set boolFrontMost to frontmost as boolean
  end tell
  if boolFrontMost is true then
    exit repeat
  end if
  delay 1
end repeat

####ワークブック開いているか?チェック
tell application "Microsoft Excel"
  set refAcvWorkBook to active workbook
  if refAcvWorkBook is (missing value) then
return "ワークブックを開いていません"
  end if
end tell
##################################
###本処理
##################################
set numLineNo to 1 as integer
repeat (numMaxRow + 1) times
  if numLineNo = 1 then
    ####シートの名前の変更
    tell application "Microsoft Excel"
tell active workbook
tell active sheet
tell cell "A1"
###A1に斜線を入れる
tell border id diagonal down
set color to {0, 0, 0}
set line style to continuous
set weight to border weight thin
end tell
end tell
end tell
end tell
    end tell
  else
    ###項番ゼロサプレス
    set strCellValue to (text -3 through -1 of (strZeroSup & (numLineNo - 1)) as text) as text
    ###セル番号整形
    set strCellNo to ("A" & (numLineNo as text)) as text
    tell application "Microsoft Excel"
tell active workbook
tell active sheet
tell cell strCellNo
##表示形式をテキストにして
set number format local to "@"
set number format to "@"
##あたいを入れる
set value to strCellValue
end tell
end tell
end tell
    end tell
  end if
  set numLineNo to numLineNo + 1 as integer
end repeat




|

[Excel]シートの使用中エリア全部でHTMLファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidPublicHTML to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeHTML)
if ocidPublicHTML is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "html"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
ocidPublicHTML's writeToURL:(ocidFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]シートの使用中エリア全部でPNGファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell

if rangeArea is (missing value) then
return "取得に失敗しました"
end if

tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "png"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]シートの使用中エリア全部でPDFファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###シートの使用中エリア全部をコピー
##########################################
tell application "Microsoft Excel"
  tell active sheet
    tell used range
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePDF)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "pdf"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲のRangeの取得

【スクリプトエディタで開く】|

tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
#####ログは以下のようになります
tell application "Microsoft Excel"
  get address local selection
    --> "$A$1:$F$12"
  get areas of cell "$A$1:$F$12" of active sheet
    --> {range "[Book1]Sheet1!$A$1:$F$12"}
end tell
結果:
{range "[Book1]Sheet1!$A$1:$F$12" of application "Microsoft Excel"}

|

[Excel]選択範囲でPNGファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell

if rangeArea is (missing value) then
return "取得に失敗しました"
end if

tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePNG)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "png"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲でPDFファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidAdobePDF to ocidPasteboard's dataForType:(refMe's NSPasteboardTypePDF)
if ocidAdobePDF is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "pdf"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
(ocidAdobePDF's writeToURL:ocidFilePathURL atomically:true)

tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択範囲でHTMLファイルにする

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

##########################################
###選択範囲をコピー
##########################################
tell application "Microsoft Excel"
  tell selection
    set cellSelection to get address local
  end tell
  tell active sheet
    tell cell cellSelection
set rangeArea to areas
    end tell
  end tell
end tell
if rangeArea is (missing value) then
return "取得に失敗しました"
end if
tell application "Microsoft Excel"
  copy range rangeArea
end tell
tell application "Microsoft Excel"
  tell active workbook
    set strFileName to (name) as text
  end tell
end tell
##########################################
###ペーストボード
##########################################
####ペーストボード宣言
set ocidPasteboard to refMe's NSPasteboard's generalPasteboard()
####中に格納されているデータを取得
set ocidPublicHTML to ocidPasteboard's stringForType:(refMe's NSPasteboardTypeHTML)
if ocidPublicHTML is (missing value) then
return "取得に失敗しました"
end if

##########################################
###ダイアログ
##########################################
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
set strFileExtension to "html"
set strDefaultName to (strFileName & "." & strFileExtension) as text

set strPromptText to "名前を決めてください" as text
set strMesText to "名前を決めてください" as text
###ダイアログ
set aliasFilePath to (choose file name strMesText default location aliasDefaultLocation default name strDefaultName with prompt strPromptText) as «class furl»
##UNIXパスに
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to refMe's NSURL's alloc()'s initFileURLWithPath:ocidFilePath isDirectory:false
####ファイル名を取得
set ocidFileName to ocidFilePathURL's lastPathComponent()
####拡張子を取得
set ocidFileExtension to ocidFilePathURL's pathExtension()
###ダイアログで拡張子を取っちゃった時対策
if (ocidFileExtension as text) is not strFileExtension then
  set ocidFilePathURL to ocidSaveFilePathURL's URLByAppendingPathExtension:(strFileExtension)
end if
##########################################
###保存
##########################################
ocidPublicHTML's writeToURL:(ocidFilePathURL) atomically:true encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)


tell application "Finder"
  open (ocidFilePathURL as alias)
end tell

|

[Excel]選択中のセル(selection)



####get address local
-->選択範囲を『アドレス』として取得する
tell application "Microsoft Excel"
set objSelecetedCell to get address local selection reference style A1
tell active workbook
tell active sheet
tell cell objSelecetedCell
###値を入れる
set value to "選択範囲address"
end tell
end tell
end tell
end tell


####selection
-->選択範囲を『レンジ』として取得する
tell application "Microsoft Excel"
set rangeSelection to selection
set listSelectionArea to (get areas of rangeSelection)
--->複数飛び地的に選択できるためリストで入る
set rangeSelectedItem to (item 1 of listSelectionArea)
tell rangeSelectedItem
###値を入れる
set value to "選択範囲range"
end tell
end tell

|

その他のカテゴリー

Acrobat Acrobat Annotation Acrobat Dialog Acrobat Form Acrobat JS Acrobat Open Acrobat Plugin Acrobat python Acrobat Reader Acrobat Sequ Acrobat Stamps Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin System Information Admin Tools Admin Users Admin Volumes Adobe Apple AppleScript AppleScript Guide AppleScript Accessibility AppleScript AppKit AppleScript Applications AppleScript AppStore AppleScript Archive AppleScript Attributes AppleScript Automator AppleScript AVAsset AppleScript AVconvert AppleScript AVFoundation AppleScript AVURLAsset AppleScript BackUp AppleScript Barcode AppleScript Bash AppleScript Basic AppleScript Basic Path AppleScript Bluetooth AppleScript BOX AppleScript Browser AppleScript Calendar AppleScript CD/DVD AppleScript Choose AppleScript Chrome AppleScript CIImage AppleScript CloudStorage AppleScript Color AppleScript com.apple.LaunchServices.OpenWith AppleScript Console AppleScript Contacts AppleScript CotEditor AppleScript CURL AppleScript current application AppleScript Date&Time AppleScript delimiters AppleScript Desktop AppleScript Device AppleScript Disk AppleScript do shell script AppleScript Dock AppleScript DropBox AppleScript eMail AppleScript Encode Decode AppleScript Error AppleScript EXIFData AppleScript ffmpeg AppleScript File AppleScript Finder AppleScript Firefox AppleScript Folder AppleScript Fonts AppleScript GIF AppleScript HTML AppleScript Icon AppleScript Illustrator AppleScript Image Events AppleScript Image2PDF AppleScript ImageOptim Applescript iWork AppleScript Javascript AppleScript Jedit AppleScript Json AppleScript Label AppleScript List AppleScript locationd AppleScript LRC AppleScript LSSharedFileList AppleScript m3u8 AppleScript MakePDF AppleScript Map AppleScript Math AppleScript Microsoft AppleScript Microsoft Edge AppleScript Microsoft Excel AppleScript Mobileconfig AppleScript Mouse AppleScript Movie AppleScript Music AppleScript NetWork AppleScript Notes AppleScript NSArray AppleScript NSBitmapImageRep AppleScript NSBundle AppleScript NSCFBoolean AppleScript NSCharacterSet AppleScript NSColor AppleScript NSColorList AppleScript NSData AppleScript NSDictionary AppleScript NSError AppleScript NSEvent AppleScript NSFileAttributes AppleScript NSFileManager AppleScript NSFont AppleScript NSFontManager AppleScript NSImage AppleScript NSIndex AppleScript NSKeyedArchiver AppleScript NSKeyedUnarchiver AppleScript NSLocale AppleScript NSMutableArray AppleScript NSMutableDictionary AppleScript NSMutableString AppleScript NSNotFound AppleScript NSNumber AppleScript NSOpenPanel AppleScript NSPasteboard AppleScript NSPDFImageRep AppleScript NSpoint AppleScript NSPredicate AppleScript NSRange AppleScript NSRegularExpression AppleScript NSRunningApplication AppleScript NSScreen AppleScript NSSize AppleScript NSString AppleScript NSStringCompareOptions AppleScript NSTask AppleScript NSTimeZone AppleScript NSURL AppleScript NSURL File AppleScript NSURLBookmark AppleScript NSURLComponents AppleScript NSURLResourceKey AppleScript NSUserDefaults AppleScript NSUUID AppleScript NSView AppleScript NSWorkspace AppleScript Numbers AppleScript OAuth AppleScript ObjC AppleScript OneDrive AppleScript Osax AppleScript PDF AppleScript PDFAnnotationWidget AppleScript PDFContext AppleScript PDFDisplayBox AppleScript PDFDocumentPermissions AppleScript PDFKit AppleScript PDFnUP AppleScript PDFOutline AppleScript Photos AppleScript Photoshop AppleScript Plist System Events AppleScript PostScript AppleScript prefPane AppleScript Preview AppleScript Python AppleScript QR AppleScript QR Decode AppleScript QuickLook AppleScript QuickTime AppleScript record AppleScript Regular Expression AppleScript Reminders AppleScript ReName AppleScript Repeat AppleScript RTF AppleScript Safari AppleScript SaveFile AppleScript ScreenCapture AppleScript ScreenSaver AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript Sort AppleScript Sound AppleScript Spotlight AppleScript SRT AppleScript StandardAdditions AppleScript stringByApplyingTransform AppleScript System Events AppleScript System Settings AppleScript TemporaryItems AppleScript Terminal AppleScript Text AppleScript Text CSV AppleScript Text TSV AppleScript TextEdit AppleScript Translate AppleScript Trash AppleScript Twitter AppleScript UI AppleScript Unit Conversion AppleScript UTType AppleScript valueForKeyPath AppleScript Video AppleScript VisionKit AppleScript Visual Studio Code AppleScript webarchive AppleScript webp AppleScript Wifi AppleScript XML AppleScript XML EPUB AppleScript XML OPML AppleScript XML Plist AppleScript XML RSS AppleScript XML SVG AppleScript XML TTML AppleScript XML webloc AppleScript YouTube AppleScript Zero Suppress Applications Barcode OnLine Tools CityCode Design iPhone List Logs lsappinfo Memo Music perl PlistBuddy pluginkit postalcode ReadMe SF Symbols character id SF Symbols Entity sips Skype Slack sqlite TCC Tools Typography Video Wacom zoom