110,571
社区成员
发帖
与我相关
我的任务
分享
string opnFileName = "D:\\dddd.xls";
if (File.Exists(opnFileName) == false)
{
return;
}
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ opnFileName + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
OleDbConnection conn = new OleDbConnection(strConn);
string strExcel = "";
OleDbDataAdapter myCommand = null;
DataSet ds = new DataSet();
strExcel = "select * from [sheet1$]";
try
{
conn.Open();
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, "dtSource"); }
catch (Exception ex)
{
MessageBox.Show("导入出错:" + ex, "错误信息");
}
finally
{
conn.Close();
conn.Dispose();
}