你好,Value 值为系统默认日期格式,Text 值为自定义日期格式。我做了一个简单的Demo ,代码如下:- private void Form1_Load(object sender, EventArgs e)
- {
- //设置数据源
- DataTable dbTable = new System.Data.DataTable();
- DataColumn colDateTime = new System.Data.DataColumn("Date", System.Type.GetType("System.DateTime"));
- dbTable.Columns.Add(colDateTime);
- dbTable.Rows.Add("12/01/2011");
- dbTable.Rows.Add("12/01/2011");
- dbTable.Rows.Add("12/01/2011");
- dbTable.Rows.Add("12/01/2011");
- dbTable.Rows.Add(System.DateTime.Now);
- dbTable.Rows.Add(System.DateTime.Now);
- dbTable.Rows.Add(System.DateTime.Now);
- dbTable.Rows.Add(System.DateTime.Now);
- this.fpSpread1.Sheets[0].DataSource = dbTable;
- this.fpSpread1.Sheets[0].Columns[0].Width = 200;
-
- }
- private void btnChangeFormat(object sender, EventArgs e)
- {
- //设置自定义日期格式
- FarPoint.Win.Spread.CellType.DateTimeCellType dateType = new FarPoint.Win.Spread.CellType.DateTimeCellType();
- DateTime a = new DateTime();
- dateType.DateSeparator = "/";
- dateType.UserDefinedFormat = "yyyy/MM/dd";
- dateType.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.UserDefined;
- this.fpSpread1.Sheets[0].Columns[0].CellType = dateType;
- MessageBox.Show(this.fpSpread1.Sheets[0].Cells[0, 0].Value.ToString());
- MessageBox.Show(this.fpSpread1.Sheets[0].Cells[0, 0].Text);
- }
复制代码 |