Spread 7 for WinForms 新增的GcDateTimeCellType (日期、时间格式)

发布时间:2013/11/19 00:11 发布者:Roger

返回博客中心

Spread 7 for WinForms 新引入了2 个新的 CellTypes:

  • GcTextBoxCellType   文本输入
  • GcDateTimeCellType 日期输入
        本文
    GcDateTimeCellType
      的功能进行说明:
    有了GcDateTimeCellType,您可以设置日期和时间格式的中的单元值。 GcDateTimeCellType还支持日期日历。您可以允许用户通过双击GcDateTime的单元格选择一个日期从日历中。

1

现在你可以访问时间,月,日,年等字段,并单独进行设置。您可以设定不同的字段在GcDateTimeCell当单元格在编辑模式下,或者单元格不处于编辑模式时。单元格用“DisplayFields”绘制不处于编辑模式时.使用“Fields”绘制在编辑模式下单元格。

Using GcDateTimeCellType

1 格式字段:您可以使用GcDateTimeCellType的进行格式化“Fields”。字段基本上都是日期字段显示处于编辑模式时。要格式化这些字段,首先你需要设置字段对象,然后将它们添加到GcDateTimeCellType的Fields集合。

  1: //Create Field objects
  2: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateDayFieldInfo dayInfo = new DateDayFieldInfo();
  3: dayInfo.BackColor = Color.Lavender;
  4: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateMonthFieldInfo monthInfo = new DateMonthFieldInfo();
  5: monthInfo.BackColor = Color.Azure;
  6: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateYearFieldInfo yearInfo = new DateYearFieldInfo();
  7: yearInfo.BackColor = Color.Crimson;
  8: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateLiteralFieldInfo literalInfo= new DateLiteralFieldInfo();
  9: literalInfo.Text = "/";
 10: //Add to GcDateTimeCell's Fields Collection
 11: GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType gcDateTimecell= new GcDateTimeCellType();
 12: gcDateTimecell.Fields.Add(monthInfo);
 13: gcDateTimecell.Fields.Add(literalInfo);
 14: gcDateTimecell.Fields.Add(dayInfo);
 15: gcDateTimecell.Fields.Add(literalInfo);
 16: gcDateTimecell.Fields.Add(yearInfo);

2. 格式化DisplayFields:类似地,你可以进行格式化DisplayFields。 DisplayFields单元格不处于编辑模式时显示的日期字段。例如,如果日期单元格不处于编辑模式,我们可以设置格式,如显示以零开头,日,月,文字和年度字段的背景色,前景色等。

  1: //Create Field objects
  2: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateDayDisplayFieldInfo day = new DateDayDisplayFieldInfo();
  3: day.ShowLeadingZero = true;
  4: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateMonthDisplayFieldInfo month = new DateMonthDisplayFieldInfo();
  5: month.ShowLeadingZero = true;
  6: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateYearDisplayFieldInfo year = new DateYearDisplayFieldInfo();
  7: year.ShowLeadingZero = true;
  8: GrapeCity.Win.Spread.InputMan.CellType.Fields.DateLiteralDisplayFieldInfo lday = new DateLiteralDisplayFieldInfo();
  9: lday.Text = "/";
 10: //Add to GcDateTimeCell's DisplayFields Collection
 11: GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType gcDateTimecell= new GcDateTimeCellType();
 12: gcDateTimecell.DisplayFields.Add(month);
 13: gcDateTimecell.DisplayFields.Add(lday);
 14: gcDateTimecell.DisplayFields.Add(day);
 15: gcDateTimecell.DisplayFields.Add(lday);
 16: gcDateTimecell.DisplayFields.Add(year)
 17: 

上面的代码显示效果截图如下:

2

 

3.ValidateMode属性:此单元格类型中的另一个重要特征是,它可以通过设置的ValidateMode属性验证用户的输入。

该属性有三个枚举:

    • GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.Validate
    • GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.ValidateEx
    • GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.ValidateNone 如果设置为ValidationMode“ValidateEx”,它会执行严格的验证,例如,2月31日不允许使用的日期

       

  1: GrapeCity.Win.Spread.InputMan.CellType.GcDateTimeCellType datecell = new CellType.GcDateTimeCellType();
  2: datecell.ValidateMode = GrapeCity.Win.Spread.InputMan.CellType.ValidateModeEx.ValidateEx;
  3: fpSpread1.Sheets[0].Cells[0, 0].CellType = datecell;
  4: 

源码下载:

  


关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网