日期:2014-05-17  浏览次数:20719 次

啊,求助,EXCEL导入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.Value2.ToString());