【发布时间】:2014-02-18 10:09:18
【问题描述】:
我有一个包含小时:分钟:秒的 excel 文件(例如:12:20:00)
我在自定义类别中设置格式单元格为 hh:mm:ss。
我正在使用 C# 读取此文件中的小时:分钟:秒。
但我收到了一个包含 "12/30/1899 12:20:00"
为什么?有人能回答吗?
如何解决这个问题?
我的代码:
string con = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtFileExcelCapture.Text + ";Extended Properties='Excel 8.0;HDR=Yes;'";
using (OleDbConnection connection = new OleDbConnection(con))
{
connection.Open();
OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
using (OleDbDataReader rows = command.ExecuteReader())
{
while (rows.Read())
{
var nameChannel = rows[0];
string HMS = rows[1].ToString();//Result is "12/30/1899 12:20:00"
}
}
}
谢谢
广
【问题讨论】:
-
您可以使用 split 从这个日期时间字段中获取时间。