在c#中读取excel文件

时间:2014-05-02 13:49:54

标签: c# excel

有没有办法将excel中的日期读作普通字符串而不是日期?我正在c#中创建一个应用程序,我可以在其中阅读和查看excel中的所有数据。当我查看数据时,日期采用以下格式:mm:dd:yyyy hh:mm:ss。

这是我阅读excel的代码

            if (filePath.Substring(filePath.LastIndexOf('.')).ToLower() == ".xlsx")
            {
                strConn = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=NO;IMEX=1;""", filePath);
            }
            else
            {
                strConn = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=NO;'", filePath);
            }

            string sql = String.Format("SELECT * FROM [{0}$A5:AG]", sheetname);
            OleDbDataAdapter adap = new OleDbDataAdapter(sql, strConn);
            adap.Fill(dset);

0 个答案:

没有答案