public ActionResult Export()
{
string table = "<table border='1px solid black'><tr><td style=\"vnd.ms-excel.numberformat:@\">编号</td><td>真实姓名</td><td>昵称</td><td>电话</td><td>数量</td><td>参与时间</td><td>状态</td><td>备注</td></tr>";
table += "<tr><td>1</td><td>2</td><td>3</td><td>4<td>5</td><td>6</td><td>6</td><td>6</td></tr>";
table += "</table>";
string fileName = "游戏活动模板" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";
Response.ContentType = "application/force-download";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<head>");
Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
//Response.ContentType = "application/excel";
//Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write("<!--[if gte mso 9]><xml>");
Response.Write("<x:ExcelWorkbook>");
Response.Write("<x:ExcelWorksheets>");
Response.Write("<x:ExcelWorksheet>");
Response.Write("<x:Name>Report Data</x:Name>");
Response.Write("<x:WorksheetOptions>");
Response.Write("<x:Print>");
Response.Write("<x:ValidPrinterInfo/>");
Response.Write("</x:Print>");
Response.Write("</x:WorksheetOptions>");
Response.Write("</x:ExcelWorksheet>");
Response.Write("</x:ExcelWorksheets>");
Response.Write("</x:ExcelWorkbook>");
Response.Write("</xml>");
Response.Write("<![endif]--> ");
Response.Write(table);
Response.End();
}ASP.NET导出excel代码
最新推荐文章于 2025-12-21 23:19:35 发布
本文介绍了一种使用C#将游戏活动数据导出为Excel文件的方法。具体包括设置表格样式、定义文件名及类型、配置HTTP响应头等步骤。此方法适用于需要批量导出数据并保持格式一致性的场景。
318

被折叠的 条评论
为什么被折叠?



