GrapeCity SPREAD for Windows Forms 12.0J サンプルコード集
和暦を表示する

日付型セル(DateTimeCellTypeクラス)のCalendarプロパティに対してJapaneseカレンダ(System.Globalization)を設定し、DateTimeFormatプロパティおよびUserDefinedFormatプロパティをそれぞれ変更することで和暦表示を行うことができます。

【実行例】

和暦表示

  • 使用できる日付書式は.NET Frameworkの仕様に準じるため、和暦の年を表す書式フィールドに「e」や「ee」は使用できません。
 private void Form1_Load(object sender, System.EventArgs e)
 {

   //デフォルトの日付型セルを設定します
   FarPoint.Win.Spread.CellType.DateTimeCellType dt1 = new FarPoint.Win.Spread.CellType.DateTimeCellType();
   fpSpread1.ActiveSheet.Cells[1, 1].CellType = dt1;
   fpSpread1.ActiveSheet.SetValue(1, 1, new DateTime(2015, 6, 15));

   //和暦を設定します
   FarPoint.Win.Spread.CellType.DateTimeCellType dt2 = new FarPoint.Win.Spread.CellType.DateTimeCellType();
   dt2.Calendar = new System.Globalization.JapaneseCalendar();
   dt2.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined;
   dt2.UserDefinedFormat = "gg yy年M月d日";
   fpSpread1.ActiveSheet.Cells[1, 2].CellType = dt2;
   fpSpread1.ActiveSheet.SetValue(1, 2, new DateTime(2015, 6, 15));

   fpSpread1.ActiveSheet.Cells[1, 1].BackColor = Color.LemonChiffon;
   fpSpread1.ActiveSheet.Cells[1, 2].BackColor = Color.LightPink;
   fpSpread1.ActiveSheet.Columns[1, 2].Width = 100;

 }
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

   'デフォルトの日付型セルを設定します
   Dim dt1 As New FarPoint.Win.Spread.CellType.DateTimeCellType
   FpSpread1.ActiveSheet.Cells(1, 1).CellType = dt1
   FpSpread1.ActiveSheet.SetValue(1, 1, New DateTime(2015, 6, 15))

   '和暦を設定します
   Dim dt2 As New FarPoint.Win.Spread.CellType.DateTimeCellType
   dt2.Calendar = New System.Globalization.JapaneseCalendar
   dt2.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined
   dt2.UserDefinedFormat = "gg yy年M月d日"
   FpSpread1.ActiveSheet.Cells(1, 2).CellType = dt2
   FpSpread1.ActiveSheet.SetValue(1, 2, New DateTime(2015, 6, 15))

   FpSpread1.ActiveSheet.Cells(1, 1).BackColor = Color.LemonChiffon
   FpSpread1.ActiveSheet.Cells(1, 2).BackColor = Color.LightPink
   FpSpread1.ActiveSheet.Columns(1, 2).Width = 100

 End Sub

 

 


Copyright © 2004 GrapeCity inc.