日付関数で和暦にするには
西暦表示しかできないのでしょうか?
iMac, iOS 10.3.3, null
西暦表示しかできないのでしょうか?
iMac, iOS 10.3.3, null
失礼致します。
日付関数とのことですが、DATE関数のことですよね。 日付のデータ入ったセルにはカスタムフォーマットを適用できることになっていて、Numbers ver. 4.1のアップデートにて、『言語や地域に合わせて、日付、時刻、通貨をカスタマイズ』できるようになったのかと思っていました。 しかしながら、『紀年法の表記:』を『平成』に指定しても、西暦で表示されてしまいますね(ver. 4.2 下図)。 Appleにフィードバックする必要がありそうです。
追記: 少し話題がずれますが、西暦の日付が入ったセルの値を和暦に変換するAppleScriptを作ってみました。 但し、変換後のセルのフォーマットは日付ではなく、テキストになってしまうので、そのセルの値を参照した計算はできなくなります。 西暦の日付が入ったセルを選択した状態で、実行します(Script Editor.app等で)。
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 date 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:theDate
set theFormatter to current application'sNSDateFormatter'snew()
theFormatter'ssetDateStyle: (current application'sNSDateFormatterLongStyle)
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 theString to theFormatter'sstringFromDate:theDate
return theString as text
end formatDate:
追記: 和暦から西暦への変換も可能でした。 旧暦にも対応している様なので便利かもしれません。
on formatDate:aJapaneseCalendarDateString
set theFormatter to current application'sNSDateFormatter'snew()
theFormatter'ssetDateStyle: (current application'sNSDateFormatterLongStyle)
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:
> [$-411]ggge"年"m"月"d"日" を使っても和暦に出来ません
これは以前ここでも問題になりましたが、以下のようにするとうまくゆくことが分かってます。
ユーザ定義で、[$-30000]ggge"年"m"月"d"日" とすれば和暦になります。
のおしまいの方のコメントにあります。
有難うございました、そうなんです西暦になってしまうので仕方なくその都度 挿入から日付を入力 を
使っています。今の処それしかない事が解りました。
ちなみにMAC版EXCELのDATE関数も、セルの書式設定からユーザー定義を選んで [$-411]ggge"年"m"月"d"日" を使っても和暦に出来ませんでした、改善されるのを待ちます。
追記:macOS High Sierra ver. 10.13のNumbers for Mac ver. 4.3では、まだ改善されていませんね。
日付関数で和暦にするには