asp.net下载 Excel文件到本地: public void FileDownLoad(string fileFullpath) { System.IO.Stream iStream = null; byte[] buffer = new Byte[10000]; int length; long dataToRead; string filepath = Server.MapPath(fileFullpath); string filename = System.IO.Path.GetFileName(filepath); try { iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); dataToRead = iStream.Length; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); // Read the bytes. while (dataToRead > 0) { // Verify that the client is connected. if (Response.IsClientConnected) { // Read the data in buffer. length = iStream.Read(buffer, 0, 10000); // Write the data to the current output stream. Response.OutputStream.Write(buffer, 0, length); // Flush the data to the HTML output. Response.Flush(); buffer = new Byte[10000]; dataToRead = dataToRead - length; } else { //prevent infinite loop if user disconnects dataToRead = -1; Response.Clear(); } } Response.End(); //没有这句会将该页面刷新后的内容追加写入文件中。 } catch (Exception ex) { } finally { if (iStream != null) { iStream.Close(); } // File.Delete(fullFilename); } } asp.net 读取Excel文件到 dataset Excel's 2007 string strConn; strConn = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=Excel 12.0;";//office 2007 OleDbConnection conn = new OleDbConnection(strConn); OleDbDataAdapter oada = new OleDbDataAdapter("select * from [Sheet1$]", strConn); DataSet ds = new DataSet(); oada.Fill(ds); conn.Close(); Excel's 97-2003 string strConn; strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileName + ";Extended Properties=Excel 8.0;";//before office 2007 OleDbConnection conn = new OleDbConnection(strConn); OleDbDataAdapter oada = new OleDbDataAdapter("select * from [Sheet1$]", strConn); DataSet ds = new DataSet(); oada.Fill(ds); conn.Close();