1
在我的要求中,我打开&读取Asp.net OLEDB中的Excel(包括2003 & 07)数据,取得了成功。使用asp.net读取excel时出错
但是,它只适用于Excel表格保持打开我们的PC,否则它会给'外部表格格式错误'。究竟是什么问题?。可以任何人告诉我光请。 这是访问权限的问题吗?
确定它与连接字符串无关。我的代码
protected void Page_Load(object sender, EventArgs e)
{
string path = @"C:\Users\abcd\Desktop\raj.xls";
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + absoluteDir + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
OleDbConnection oledbConn = new OleDbConnection(connStr);
try
{
oledbConn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", oledbConn);
OleDbDataAdapter oleda = new OleDbDataAdapter();
oleda.SelectCommand = cmd;
DataSet ds = new DataSet();
oleda.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
catch (Exception err)
{
}
finally
{
// Close connection
oledbConn.Close();
}
}
预先感谢