和暦から西暦への自動変換はできますか?
先日、MacBook Airの新規購入に伴い、NumbersをDownloadしました。
そこで質問があるのですが、たとえば、あるセルに"H25/11/02"と入力してリターンキーを押すと、自動的に"2013/11/02"と入力されるような関数式はないのでしょうか? Excelにはそのような関数式があり重宝していたのですが。
MacBook Air (11-inch Mid 2013)
先日、MacBook Airの新規購入に伴い、NumbersをDownloadしました。
そこで質問があるのですが、たとえば、あるセルに"H25/11/02"と入力してリターンキーを押すと、自動的に"2013/11/02"と入力されるような関数式はないのでしょうか? Excelにはそのような関数式があり重宝していたのですが。
MacBook Air (11-inch Mid 2013)
度々、失礼致します。
AppleScriptでObjective-CのFoundationフレームワークを使うことで、和暦から西暦への変更ができました。
"H25/11/02"とテキスト(日付のフォーマットではない)が入力されたセルを選択した状態で実行します。 実行後に入力される値は日付のフォーマットになります。 複数のセルでの変更も可能です。
macOS High Sierra ver. 10.3, Numbers ver. 4.3, AppleScript ver. 2.7で動作を確認しました。
"平成27年11月02日"のフォーマットの日付(テキスト)を変換する場合は、NSDateFormatterShortStyleの代わりに、NSDateFormatterLongStyleを使います。
use framework "Foundation"
tell front document of application "Numbers"
tell active sheet
set theTable to the first item of (tables whose class of selection range is range)
tell theTable
set theRange to its selection range
tell theRange
set valueList to its value of cells
set theCount to length of valueList
repeat with i from 1 to theCount
set theValue to item i of valueList
if class of theValue is text then
set value of its cell i to (my formatDate:theValue)
end if
end repeat
end tell
end tell
end tell
end tell
on formatDate:aJapaneseCalendarDateString
set theFormatter to current application'sNSDateFormatter'snew()
theFormatter'ssetDateStyle: (current application'sNSDateFormatterShortStyle)
theFormatter'ssetTimeStyle: (current application'sNSDateFormatterNoStyle)
theFormatter'ssetDoesRelativeDateFormatting:false
set japaneseCalendar to current application'sNSCalendar'scalendarWithIdentifier: (current application'sNSCalendarIdentifierJapanese)
theFormatter'ssetCalendar:japaneseCalendar
set theLocale to current application'sNSLocale'salloc()'s initWithLocaleIdentifier:"ja_JP"
theFormatter'ssetLocale:theLocale
set aString to current application'sNSString'sstringWithString:aJapaneseCalendarDateString
set aDate to theFormatter'sdateFromString:aString
return aDate as date
end formatDate:
度々、失礼致します。
AppleScriptでObjective-CのFoundationフレームワークを使うことで、和暦から西暦への変更ができました。
"H25/11/02"とテキスト(日付のフォーマットではない)が入力されたセルを選択した状態で実行します。 実行後に入力される値は日付のフォーマットになります。 複数のセルでの変更も可能です。
macOS High Sierra ver. 10.3, Numbers ver. 4.3, AppleScript ver. 2.7で動作を確認しました。
"平成27年11月02日"のフォーマットの日付(テキスト)を変換する場合は、NSDateFormatterShortStyleの代わりに、NSDateFormatterLongStyleを使います。
use framework "Foundation"
tell front document of application "Numbers"
tell active sheet
set theTable to the first item of (tables whose class of selection range is range)
tell theTable
set theRange to its selection range
tell theRange
set valueList to its value of cells
set theCount to length of valueList
repeat with i from 1 to theCount
set theValue to item i of valueList
if class of theValue is text then
set value of its cell i to (my formatDate:theValue)
end if
end repeat
end tell
end tell
end tell
end tell
on formatDate:aJapaneseCalendarDateString
set theFormatter to current application'sNSDateFormatter'snew()
theFormatter'ssetDateStyle: (current application'sNSDateFormatterShortStyle)
theFormatter'ssetTimeStyle: (current application'sNSDateFormatterNoStyle)
theFormatter'ssetDoesRelativeDateFormatting:false
set japaneseCalendar to current application'sNSCalendar'scalendarWithIdentifier: (current application'sNSCalendarIdentifierJapanese)
theFormatter'ssetCalendar:japaneseCalendar
set theLocale to current application'sNSLocale'salloc()'s initWithLocaleIdentifier:"ja_JP"
theFormatter'ssetLocale:theLocale
set aString to current application'sNSString'sstringWithString:aJapaneseCalendarDateString
set aDate to theFormatter'sdateFromString:aString
return aDate as date
end formatDate:
失礼致します。 Numbersのヴァージョンは3.0でしょうか? 残念ですが、日付関数の一覧をみると、和暦がら西暦に変換するようなものがなさそうです。 → 日付と時刻関数
”H25/11/02"と入力したセルをA1とすると、それを参照する形で別のセルに、=Date(mid(a1,2,2) + 1988, mid(a1,5,2), right(a1,2)) と入力するというのも方法の一つかもしれません。
いやぁ、そうなんですよね。Numbersって関数や表示形式の設定が少なすぎるのですよね。
Excelから移行したくても出来ないの理由がこれだったりします。
T2 2Tさん、response有難うございます。
すみません、Numbersのバージョンは3.0です。
なるほど、自動変換は無理なようですね。
もう1列別に作って入力できるようにするしかないようですね。
大変参考になりました。有難うございます。
やすどんさん、そうですね。
Numbersに完全移行しようと目論んでいたのですが、やはりExcelは手放せないようです・・・
度々、失礼致します。 Numbers v3.0にはAppleScript用の辞書も無いので、機能の拡張も制限されます。 まだExcelには敵いませんね(無料なので文句も言えず)。 今回のヴァージョンアップに期待していたのですが、ちょっと残念です。
T2 2Tさん、たびたび有難うございます。
確かに今回から無料になったので、あまり文句は言えませんね。
実は以前購入したMicrosoft Office Home and Business 2011 for MacのDiscを紛失してしまい、新しいAirにinstallできない状況でしたので、もしNumbersでExcelの代用ができればと思っていたのです。
実際Numbersを少し使ってみて、慣れの問題もあるのでしょうが、やはり使い勝手に関してはExcelに一日の長があると感じました。
またOfficeを買い直さなくてはと思ってます・・・
surgeonさん、こんちは。 試しに、SkyDriveのExcel Web Appでセルの表示形式を『短い日付形式』にして、”H25/11/02”と入力すると、自動的に”2013/11/02”と表示してくれましたよ。 私は10年くらい前にでた『Office:mac v.X』を購入した後はアップグレードしていないのですが(私には高額すぎて)、簡単なOffice書類であれば無料のSkyDriveを使って編集したり、勤務先のWindows-PCにリモートデスクトップ接続を行なって、Windows-PCにインストールされているOfficeを使って書類の編集を行なっています。 SkyDriveも無料ですし、Microsoft Remote Desktopも無料なので、とても安上がりにやっています。
和暦から西暦への自動変換はできますか?