展开全部
创建一个一般处理程序
context.Response.Clear();
context.Response.Buffer = true;
context.Response.Charset = "utf-8";
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + context.Server.UrlEncode("Excel名称") + ".xls");
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
context.Response.ContentType = "application/vnd.ms-excel";//设置输出文件类型为excel文件。
context.Response.Write("表头1\t");
context.Response.Write("表头2\t");
context.Response.Write("表头3\t");
context.Response.Write("\n");
foreach (DataRow dr in dt.Rows)
{
context.Response.Write(dr["数据1"] + "\t");
context.Response.Write(dr["数据2"] + "\t");
context.Response.Write(dr["数据3"] + "\t");
context.Response.Write("\n");
}
context.Response.End();
context.Response.Clear();
context.Response.Buffer = true;
context.Response.Charset = "utf-8";
context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + context.Server.UrlEncode("Excel名称") + ".xls");
context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
context.Response.ContentType = "application/vnd.ms-excel";//设置输出文件类型为excel文件。
context.Response.Write("表头1\t");
context.Response.Write("表头2\t");
context.Response.Write("表头3\t");
context.Response.Write("\n");
foreach (DataRow dr in dt.Rows)
{
context.Response.Write(dr["数据1"] + "\t");
context.Response.Write(dr["数据2"] + "\t");
context.Response.Write(dr["数据3"] + "\t");
context.Response.Write("\n");
}
context.Response.End();
追问
追答
当然可以,你在网上下个ExcelHelper帮助类,就可以实现这种布局方式
你也可以用上面的方式,先组建Html样式,输出来也行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询