和暦から西暦への自動変換はできますか?

先日、MacBook Airの新規購入に伴い、NumbersをDownloadしました。

そこで質問があるのですが、たとえば、あるセルに"H25/11/02"と入力してリターンキーを押すと、自動的に"2013/11/02"と入力されるような関数式はないのでしょうか? Excelにはそのような関数式があり重宝していたのですが。

MacBook Air (11-inch Mid 2013)

投稿日 2013/11/01 06:11

返信
スレッドに付いたマーク ランキングトップの返信

投稿日 2017/10/27 05:09

度々、失礼致します。


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:

返信: 8
スレッドに付いたマーク ランキングトップの返信

2017/10/27 05:09 surgeon への返信

度々、失礼致します。


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:

2013/11/01 07:04 surgeon への返信

失礼致します。 Numbersのヴァージョンは3.0でしょうか? 残念ですが、日付関数の一覧をみると、和暦がら西暦に変換するようなものがなさそうです。 → 日付と時刻関数


”H25/11/02"と入力したセルをA1とすると、それを参照する形で別のセルに、=Date(mid(a1,2,2) + 1988, mid(a1,5,2), right(a1,2)) と入力するというのも方法の一つかもしれません。

2013/11/03 21:30 T22T への返信

T2 2Tさん、たびたび有難うございます。

確かに今回から無料になったので、あまり文句は言えませんね。

実は以前購入したMicrosoft Office Home and Business 2011 for MacのDiscを紛失してしまい、新しいAirにinstallできない状況でしたので、もしNumbersでExcelの代用ができればと思っていたのです。

実際Numbersを少し使ってみて、慣れの問題もあるのでしょうが、やはり使い勝手に関してはExcelに一日の長があると感じました。

またOfficeを買い直さなくてはと思ってます・・・

2013/11/03 22:05 surgeon への返信

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も無料なので、とても安上がりにやっています。

このスレッドはシステム、またはAppleコミュニティチームによってロックされました。 問題解決の参考になる情報であれば、どの投稿にでも投票いただけます。またコミュニティで他の回答を検索することもできます。

和暦から西暦への自動変換はできますか?

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple Account を使ってご参加ください。