啊,求助,EXCEL导入datagridview, 日期显示的是一串数字。。。怎么回事啊?代码见内。
比如在EXCEL中是2011/11/11,导入到datagridview就是一串数字。
求如何在datagridview显示的也是日期啊。。。
导入Excel
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Excel文件(*.xls)|*.xls";
if (ofd.ShowDialog() == DialogResult.OK)
{
string filename = ofd.FileName;
ExcelToDataGridView(filename);
}
}
private void ExcelToDataGridView(string filename)
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook workbook;
Microsoft.Office.Interop.Excel.Worksheet worksheet;
object oMissing = System.Reflection.Missing.Value;
workbook = excel.Workbooks.Open(filename, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
worksheet = (Worksheet)workbook.Worksheets[1];
int rowCount = worksheet.UsedRange.Rows.Count;
int colCount = worksheet.UsedRange.Columns.Count;
Microsoft.Office.Interop.Excel.Range range1;
System.Data.DataTable dt = new System.Data.DataTable();
for (int i = 0; i <= colCount; i++)
{
try
{
range1 = worksheet.get_Range((object)worksheet.Cells[1, i + 1], (object)worksheet.Cells[1, i + 1]);
dt.Columns.Add(range1.Va