当把FlexGrid的列的DataType设置成Object的时候,赋值DateTime类型的值,在软件界面中显示正常,但导出后显示格式错误
控件版本
初始化数据源数据
form前端界面
form后台代码
运行后FlexGrid中显示的数据
导出后Excel中显示的数据
数据源:
public DataTable InitTableDate()
{
DataTable dt = new DataTable();
dt.Clear();
for (int i = 0; i < 7; i++)
{
if (i == 0 || i == 1)
dt.Columns.Add((i + 1).ToString(), typeof(DateTime));
else if (i == 2 || i == 3)
dt.Columns.Add((i + 1).ToString(), typeof(object));
else
dt.Columns.Add((i + 1).ToString(), typeof(string));
}
for (int j = 0; j < 4; j++)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < 7; i++)
{
if (i == 0 || i == 1)
dr = DateTime.Now;
else if (i == 2 || i == 3)
dr = DateTime.Now;
else
dr = DateTime.Now.ToShortDateString();
}
dt.Rows.Add(dr);
}
return dt;
}
后台代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using C1.Win.C1FlexGrid;
namespace C1Test
{
public partial class FlexGridExport : Form
{
public FlexGridExport()
{
InitializeComponent();
}
private void FlexGridExport_Load(object sender, EventArgs e)
{
this.fgvDateTest.SetDataBinding(InitData.Instance.InitTableDate(), "", false);
}
private void btnExport_Click(object sender, EventArgs e)
{
this.fgvDateTest.SaveExcel("dateTest.xlsx", "sheet1",
FileFlags.IncludeFixedCells | FileFlags.AsDisplayed);
}
}
} |