"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""" "HDR=Yes;" indicates that the first row contains columnnames, not data "IMEX=1;" tells the driver to always read "intermixed" data columns as text TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.IMEX=1:把所有单元格数据当成字符串来读.
"HDR=Yes;" indicates that the first row contains columnnames, not data
"IMEX=1;" tells the driver to always read "intermixed" data columns as text
TIP! SQL syntax: "SELECT * FROM [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.IMEX=1:把所有单元格数据当成字符串来读.
public DataSet ExcelToDS(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Path + ";" +
"Extended Properties=Excel 8.0;HDR=Yes;IMEX=1;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcelPSID = "";
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcelPSID="select * from [Sheet1$]";
myCommand = new OleDbDataAdapter(strExcelPSID, strConn);
ds = new DataSet();
myCommand.Fill(ds,"table1");
conn.Close();
return ds;
}
而且导入Excel后,这个文件就不能打开了,我要把aspnet_wp进程关掉才能打开(XP系统)。我不是把连接关闭了吗?怎么还是不能释放?