public void ExPort(){
System.IO.StringWriter sw = new System.IO.StringWriter();
string sql="";
Datable dt=DBhelper.qery(sql);//查询出要导出内容的表
String s="";
int rowcount = 50;//导出的行数
int ColumnCount = dt.Columns.Count;//d导出表的列数
for (int i = 0; i < rowcount; i++)
{
for (int j = 0; j < ColumnCount; j++)
{
s = s + dt.Rows[i][j] + "\t";
}
}
sw.WriteLine(s.Trim());
s = "";
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment; filename=RechargeSearch.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
效果图如下
友情提示,如果会提示缺少哪些组件,在我的工具箱里面都有,需要的自己去下载