|
楼主 |
发表于 2013-4-25 10:00:49
|
显示全部楼层
[code=csharp] /// <summary>
/// 由EXCEL转换成DataTable(Excel绝对路径) ICU病人日志
/// </summary>
/// <param name="excelPath"></param>
/// <returns></returns>
public static DataTable GetDataTableICU1(string excelPath)
{
string selectCommandText = "select * from [sheet1$A3:F35] ";
DataSet dataSet = null;
dataSet = new DataSet();
new OleDbDataAdapter(selectCommandText, ExcelConnectionString(excelPath)).Fill(dataSet);
if (dataSet.Tables.Count > 0)
{
return dataSet.Tables[0];
}
return null;
}
/// <summary>
/// 构造Excel的连接字符串
/// </summary>
/// <param name="excelPath"></param>
/// <returns></returns>
private static string ExcelConnectionString(string excelPath)
{
if (!excelPath.ToLower().Contains(".xlsx"))
{
return string.Format(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;",
excelPath);
}
return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'",
excelPath);
}
[/code] |
|