110,545
社区成员
发帖
与我相关
我的任务
分享
private string GetConnectString()
{
try
{
if (!File.Exists(txtSourceFile.Text))
return string.Empty;
string strConn;
string excelFilename = txtSourceFile.Text;
if (excelFilename.EndsWith("xls", StringComparison.InvariantCultureIgnoreCase))
{
strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=" + excelFilename + ";" + "Extended Properties=\"Excel 8.0;HDR=No\"";
}
else if (excelFilename.EndsWith("xlsx", StringComparison.InvariantCultureIgnoreCase))
{
//strConn = @"Data Source=" + _strExcelFilename +
// ";Provider=Microsoft.ACE.OLEDB.12.0; Extended Properties=Excel 12.0;";
strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=" + excelFilename + ";" +
"Extended Properties=\"Excel 12.0 Xml;HDR=No\"";
}
else
return string.Empty;
return strConn;
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.ToString());
return string.Empty;
}
}