总的来说:
DataGrid生成的Excel不能用下面的代码读取;报错:外部表不是预期的格式。
新建excel文件,填写内容后读取,就能读取成功。
代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string strSQL ="select * from stu_info";
string strConnection = "server=(local);database=temp;uid=sa;pwd=;"; SqlConnection objConnection = new SqlConnection(strConnection);
SqlDataAdapter objDataAdapter = new SqlDataAdapter(strSQL,objConnection); DataSet objDataSet = new DataSet(); objDataAdapter.Fill(objDataSet,"qq");
DataView objDataView = new DataView(objDataSet.Tables["qq"]); DataGrid2.DataSource = objDataView;
DataGrid2.DataBind(); }
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Clear(); 
Response.Buffer= true; 
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls"); //设置文件名
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
this.EnableViewState = false;    
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); 
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
DataGrid2.RenderControl(oHtmlTextWriter); //MyDataGrid是DataGrid的Id
Response.Write(oStringWriter.ToString());
Response.End();


}
private void Button1_Click(object sender, System.EventArgs e)
{
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\bbb.xls;Extended Properties='Excel 9.0;HDR=Yes;IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet,"[sheet1$]");
DataGrid1.DataSource = myDataSet.Tables["[sheet1$]"].DefaultView;
DataGrid1.DataBind(); }高手帮忙,谢谢~~