日付関数で和暦にするには

西暦表示しかできないのでしょうか?

iMac, iOS 10.3.3, null

投稿日 2017/08/24 19:25

返信
返信: 6

2017/08/25 19:26 cyberdog33 への返信

失礼致します。 


日付関数とのことですが、DATE関数のことですよね。 日付のデータ入ったセルにはカスタムフォーマットを適用できることになっていて、Numbers ver. 4.1のアップデートにて、『言語や地域に合わせて、日付、時刻、通貨をカスタマイズ』できるようになったのかと思っていました。 しかしながら、『紀年法の表記:』を『平成』に指定しても、西暦で表示されてしまいますね(ver. 4.2 下図)。 Appleにフィードバックする必要がありそうです。


ユーザがアップロードしたファイル

2017/10/25 05:29 cyberdog33 への返信

追記: 少し話題がずれますが、西暦の日付が入ったセルの値を和暦に変換する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:

2017/10/27 05:22 T22T への返信

追記: 和暦から西暦への変換も可能でした。 旧暦にも対応している様なので便利かもしれません。


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:

2017/08/25 19:59 cyberdog33 への返信

> [$-411]ggge"年"m"月"d"日" を使っても和暦に出来ません


これは以前ここでも問題になりましたが、以下のようにするとうまくゆくことが分かってます。

ユーザ定義で、[$-30000]ggge"年"m"月"d"日" とすれば和暦になります。

Excel和暦表示を表示したい。

のおしまいの方のコメントにあります。

2017/08/25 19:26 T22T への返信

有難うございました、そうなんです西暦になってしまうので仕方なくその都度 挿入から日付を入力 を

使っています。今の処それしかない事が解りました。

 ちなみにMAC版EXCELのDATE関数も、セルの書式設定からユーザー定義を選んで [$-411]ggge"年"m"月"d"日" を使っても和暦に出来ませんでした、改善されるのを待ちます。

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

日付関数で和暦にするには

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