[]
You can specify format settings for the era if the culture has been set to "ja-jp".
The following table lists the format options and the Japanese and English culture equivalents.
Keyword | Japanese Culture | English Culture |
---|---|---|
g | Display the era name in the alphabet (M, T, S, H, R) | |
gg | Display the first character (DBCS) era (明, 大, 昭, 平, 令) | |
ggg | Display the full (DBCS) era (明治, 大正, 昭和, 平成, 令和) | |
gggg (plus any additional "g" characters) | Same as "ggg" | |
e | Display the nengo year as a single-digit number when possible (1-??) | Same as "y" |
ee | Display the nengo year as a two-digit number when possible (01-??) | Same as "yy" |
eee (plus any additional "e" characters) | Same as "ee" | Same as "yyyy" |
y | Same as 'e' when after 'g'; otherwise, same as en culture | Display the year as a number without a leading zero (0 - 99) |
yy | Same as 'ee' when after 'g'; otherwise, same as en culture | Display the year as a number with a leading zero (00 - 99) |
yyy | Same as 'ee' when after 'g'; otherwise, same as en culture | Display the year as a number without a leading zero (1 - 9999) |
yyyy | Same as 'ee' when after 'g'; otherwise, same as en culture | Same as "yyy" |
The following code sample sets the era formatting.
GC.Spread.Common.CultureInfo.eras = [
{name: "明治", abbreviation: "明", symbol: "M", startDate: "1868-09-08", shortcuts: "1,M"},
{name: "大正", abbreviation: "大", symbol: "T", startDate: "1912-07-30", shortcuts: "2,T"},
{name: "昭和", abbreviation: "昭", symbol: "S", startDate: "1926-12-25", shortcuts: "3,S"},
{name: "平成", abbreviation: "平", symbol: "H", startDate: "1989-01-08", shortcuts: "4,H"},
{name: "令和", abbreviation: "令", symbol: "R", startDate: "2019-05-01", shortcuts: "5,R"}
];
SpreadJS supports [$-ja-JP-x-gannen]
formatter to display the first year as "元" and [$-411]ggg e
formatter to display the first year as "1". This can be explained using the below example:
Date | Formatter | Result |
---|---|---|
2019/12/1 | [$-ja-JP-x-gannen]ggg e"年"m"月"d"日" | 令和 元年12月1日 |
2019/12/1 | [$-411]ggg e"年"m"月"d"日" | 令和 1年12月1日 |
The following code sample formats a date in a cell.
// initializing Spread
var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });
// get the activesheet
var activeSheet = spread.getActiveSheet();
var date1 = new Date(1989, 1, 8, 2, 3, 7, 325);
var date2 = new Date(2019, 8, 1, 6, 2, 8, 321);
var date3 = new Date(2020, 7, 1, 2, 1, 5, 311);
activeSheet.setValue(0, 0, '[$-411]ggge"年"m"月"d"日" 午前/午後');
activeSheet.setValue(0, 1, date1);
// set formatter for Cell[0,1]
activeSheet.setFormatter(0, 1, '[$-411]ggge"年"m"月"d"日" 午前/午後');
activeSheet.setValue(1, 0, '[$-ja-JP-x-gannen]ggg e"年"m"月"d"日"');
activeSheet.setValue(1, 1, date2);
// set formatter for Cell[1,1]
activeSheet.setFormatter(1, 1, '[$-ja-JP-x-gannen]ggg e"年"m"月"d"日"');
activeSheet.setValue(2, 0, '[$-411]ggg e"年"m"月"d"日"');
activeSheet.setValue(2, 1, date2);
// set formatter for Cell[2,1]
activeSheet.setFormatter(2, 1, '[$-411]ggg e"年"m"月"d"日"');
activeSheet.setValue(3, 0, '[$-ja-JP-x-gannen]ggg e"年"mm"月"dd"日"');
activeSheet.setValue(3, 1, date3);
// set formatter for Cell[3,1]
activeSheet.setFormatter(3, 1, '[$-ja-JP-x-gannen]ggg e"年"mm"月"dd"日"');
// set column width
activeSheet.setColumnWidth(0, 300.0, GC.Spread.Sheets.SheetArea.viewport);
activeSheet.setColumnWidth(1, 200.0, GC.Spread.Sheets.SheetArea.viewport);