按html格式 导出 excel

/// <summary>
/// 导出EXCEL-HTML
/// </summary>
/// <param name="strFileName">文件名称</param>
/// <param name="excelHtml">html内容</param>
public static void ExpExcelHtml(string strFileName, string excelHtml)
{
string ExcelExt = ".xls";
//清除Response缓存内容
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
strFileName = !strFileName.ToLower().Trim().EndsWith(ExcelExt) ? strFileName + ExcelExt : strFileName;
//确定字符的编码格式
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName));
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//消除乱码特别设定
string strExcel = "";
strExcel = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">";
strExcel += excelHtml;
HttpContext.Current.Response.Write(strExcel);
HttpContext.Current.Response.End();
}
阅读更多
文章标签: html string excel
想对作者说点什么? 我来说一句

html格式导出excel

steveguoshao steveguoshao

2013-05-27 13:26:15

阅读数:3050

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭