ASP 最简单导出excel的方法
来源:互联网 发布:linux 用户提权 编辑:程序博客网 时间:2024/05/17 18:41
{
Export("application/excel", DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
}
private void Export(string FileType, string FileName)
{
StringBuilder htmltable = new StringBuilder();
htmltable.Append("<table border='1' cellspacing='0' cellpadding='0'>");//添加黑色边框 (选用)
htmltable.AppendFormat("<tr><td rowspan='2' style='width: 100px;'>" + Label5.Text + "</td><td align='center' style='width: 300px;' colspan='3'>" + Label6.Text + "</td></tr><tr><td style='width: 100px;'>市台</td><td style='width: 100px;'>中央台</td><td style='width: 100px;'>省台</td></tr><tr><td style='width: 100px;'>平均</td><td align='left'>" + Label7.Text + "</td><td align='left'>" + Label8.Text + "</td><td align='left'>" + Label9.Text + "</td></tr>");//添加表头
foreach (RepeaterItem item in rpData_Result.Items) //遍历表格
{
Label Label1 = (Label)item.FindControl("Label1");
Label Label2 = (Label)item.FindControl("Label2");
Label Label3 = (Label)item.FindControl("Label3");
Label Label4 = (Label)item.FindControl("Label4");
htmltable.AppendFormat("<tr><td align=\"left\">{0}</td><td align=\"left\">{1}</td><td align=\"left\">{2}</td><td align=\"left\">{3}</td></tr>", Label1.Text, Label2.Text, Label3.Text, Label4.Text);
}
htmltable.Append("</table>");
Response.Clear();
Response.BufferOutput = true;
Response.Charset = "utf-8";
//Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.Write(AddExcelHead());//显示网格线(选用)
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
string content = htmltable.ToString();
Response.Write("<html xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns:m='http://schemas.microsoft.com/office/2004/12/omml' xmlns='http://www.w3.org/TR/REC-html40'><head></head><body lang=ZH-CN>" + content);
Response.End();
}
public static string AddExcelHead()//显示网格线(选用)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
sb.Append(" <head>");
sb.Append(" <!--[if gte mso 9]><xml>");
sb.Append("<x:ExcelWorkbook>");
sb.Append("<x:ExcelWorksheets>");
sb.Append("<x:ExcelWorksheet>");
sb.Append("<x:Name></x:Name>");
sb.Append("<x:WorksheetOptions>");
sb.Append("<x:Print>");
sb.Append("<x:ValidPrinterInfo />");
sb.Append(" </x:Print>");
sb.Append("</x:WorksheetOptions>");
sb.Append("</x:ExcelWorksheet>");
sb.Append("</x:ExcelWorksheets>");
sb.Append("</x:ExcelWorkbook>");
sb.Append("</xml>");
sb.Append("<![endif]-->");
sb.Append(" </head>");
sb.Append("<body>");
return sb.ToString();
}
- ASP 最简单导出excel的方法
- asp导出excel最简单最有效的方法
- ASP导出为Word或Excel的最简单方法
- asp导出excel文件最简单方便的方法
- 最简单的Asp导出Excel
- PHP导出Excel最简单的方法
- asp生成Excel最简单的方法
- ExcelUtils -- excel模板引擎,导出excel最简单的方法
- 最简单的Excel导出
- excel最简单的导入导出
- asp.Net导出Excel的快捷方法
- Asp.NET导出excel的方法
- asp中导出Excel的方法
- ASP导出Excel数据最簡單的方法
- asp.net 导出Excel/Word的方法
- asp.net导出Excel的方法
- asp导出excel的四种方法
- winform中 将listview的数据导出至 excel (最简单的方法)
- 多标签图像分类任务的评价方法-mAP
- Lucene .Net + 盘古分词 学习资料
- Java工厂设计模式
- html5--h5的改进优势
- Spring的监听事件ApplicationListener和ApplicationEvent及@EventListener用法
- ASP 最简单导出excel的方法
- java.lang.NoSuchMethodError
- CodeForces
- javascript函数细说,函数也能做对象
- InstantiationAwareBeanPostProcessor
- java抽象类和接口干货满满
- JAVA之经典算法一
- liunx 操作命令记录
- Java(8-3 01)多线程同步