LoginSignup
0
0

More than 5 years have passed since last update.

Excelの選択範囲をUnicodeで書出すAppleScript

Posted at

FileMakerもくもく会#14の成果のAppleScript
(FileMaker?)

標準の保存ではUTF-16で保存はできるものの、Scriptには対応してなかったのでちょっと考えてみました。
データの範囲選択等色々考えたのですが、闇が広がってきたので書出す範囲をあらかじめ選択しておいてもらう方法にしました。

クリップボード汚染します(苦笑

それと、なぜか連続で実行するとエラーになります。(なんで??)

Excelと同階層にタブ区切りテキストを書き出します。


tell application "Microsoft Excel"
    activate
    copy range of selection
    set TabText to get the clipboard

    set DocPath to full name of active workbook

    my SaveTabText(DocPath, TabText)

end tell


on SaveTabText(DocPath, TabText)

    tell application "Finder" to set aExt to name extension of (info for (DocPath as alias))

    set SaveTabText to my Delimiters(DocPath as Unicode text, aExt, "txt")
    set SaveTabText to quoted form of POSIX path of SaveTabText

    set shcmd to "echo " & TabText & " > " & SaveTabText
    do shell script shcmd
end SaveTabText

on Delimiters(theText, serchStr, replaceStr)
    set OriginalDelimiters to AppleScript's text item delimiters
    set AppleScript's text item delimiters to serchStr
    set theText to text items of theText
    set AppleScript's text item delimiters to replaceStr
    set theText to theText as string
    set AppleScript's text item delimiters to OriginalDelimiters
    return theText
end Delimiters

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0