execl导出--在线等 execl导出已经实现了,使用nopi实现的,现在的问题是导出的数据有一部分介绍,是html的,导出以后显示的是html代码,能不能导出以后查看时显示的是解析以后内容,就是和从浏览器查看一样的效果。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void OutPutExcel(string html,string filename) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Charset = "GB2312"; //设置了类型为中文防止乱码的出现 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename+".xls")); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文 HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Write(html); HttpContext.Current.Response.End(); } 封装好的方法,,,直接调用就好,,, public static void OutPutExcel(string html,string filename) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Charset = "GB2312"; //设置了类型为中文防止乱码的出现 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename+".xls")); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文 HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.Write(html); HttpContext.Current.Response.End(); } 封装好的方法,,,直接调用就好,,, GemBox.ExcelLite 用这个! 同志们,好像你们说的没有我要的,我要的是怎么设置导出时execl列显示的格式,可以显示html代码格式的单元格格式另外不要用导出html代码,另存为xls的方法的,我现在已经导出了标准格式的execl文件,主要是显示html代码问题,比如商品的介绍,存储的是html代码,导出了显示的还是代码,要求显示的是和浏览器一样的效果 #region 导出为Excel public override void VerifyRenderingInServerForm(Control control) { // Confirms that an HtmlForm control is rendered for } private void ToExcel(Control ctl, string FileName) { HttpContext.Current.Response.Charset = "UTF-8"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; HttpContext.Current.Response.ContentType = "application/ms-excel"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName); ctl.Page.EnableViewState = false; System.IO.StringWriter tw = new System.IO.StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); ctl.RenderControl(hw); HttpContext.Current.Response.Write(tw.ToString()); HttpContext.Current.Response.End(); } private void toExcelClk() { gvSysUser.AllowPaging = false; gvSysUser.AllowSorting = false; gvSysUser.DataBind(); ToExcel(gvSysUser, "OFS_Data.xls"); gvSysUser.AllowPaging = true; gvSysUser.AllowSorting = true; gvSysUser.DataBind(); } #endregion或者/// <summary> /// 将Web控件导出 /// </summary> /// <param name="source">控件实例</param> /// <param name="type">类型:Excel或Word</param> public void ExpertControl(System.Web.UI.Control source, DocumentType type) { //设置Http的头信息,编码格式 if (type == DocumentType.Excel) { //Excel Response.AppendHeader("Content-Disposition","attachment;filename=result.xls"); Response.ContentType = "application/ms-excel"; } else if (type == DocumentType.Word) { //Word Response.AppendHeader("Content-Disposition","attachment;filename=result.doc"); Response.ContentType = "application/ms-word"; } Response.Charset = "UTF-8"; Response.ContentEncoding = System.Text.Encoding.UTF8; //关闭控件的视图状态 source.Page.EnableViewState =false; //初始化HtmlWriter System.IO.StringWriter writer = new System.IO.StringWriter() ; System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer); source.RenderControl(htmlWriter); //输出 Response.Write(writer.ToString()); Response.End(); } //文档类型 public enum DocumentType { Word, Excel } 在ASP.NET中新注册用户如何获取他的硬盘号? 求明白人帮看下 问个简单的正则表达式 FTP的小问题 为什么循环dataset或datareader值为空 高手来帮个忙! ASP.Net中无法创建框架的难题。。。。 Page_Load中Response.Redirect后怎样获取上页地址 怎么在vs.net中实现DW中的模板功能? SqlConnection对象在函数结束时关闭还是在Dispose方法中关闭? 一个简单问题 未将对象引用设置到对象的实例,怎么解决呢?
{ HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "GB2312";
//设置了类型为中文防止乱码的出现
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename+".xls"));
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//设置输出流为简体中文
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Write(html);
HttpContext.Current.Response.End();
}
封装好的方法,,,直接调用就好,,,
{ HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "GB2312";
//设置了类型为中文防止乱码的出现
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename+".xls"));
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
//设置输出流为简体中文
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Write(html);
HttpContext.Current.Response.End();
}
封装好的方法,,,直接调用就好,,,
GemBox.ExcelLite 用这个!
另外不要用导出html代码,另存为xls的方法的,我现在已经导出了标准格式的execl文件,主要是显示html代码问题,比如商品的介绍,存储的是html代码,导出了显示的还是代码,要求显示的是和浏览器一样的效果
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
} private void ToExcel(Control ctl, string FileName)
{
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + FileName);
ctl.Page.EnableViewState = false;
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
} private void toExcelClk()
{
gvSysUser.AllowPaging = false;
gvSysUser.AllowSorting = false;
gvSysUser.DataBind();
ToExcel(gvSysUser, "OFS_Data.xls");
gvSysUser.AllowPaging = true;
gvSysUser.AllowSorting = true;
gvSysUser.DataBind();
}
#endregion或者/// <summary>
/// 将Web控件导出
/// </summary>
/// <param name="source">控件实例</param>
/// <param name="type">类型:Excel或Word</param>
public void ExpertControl(System.Web.UI.Control source, DocumentType type)
{
//设置Http的头信息,编码格式
if (type == DocumentType.Excel)
{
//Excel
Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
Response.ContentType = "application/ms-excel";
}
else if (type == DocumentType.Word)
{
//Word
Response.AppendHeader("Content-Disposition","attachment;filename=result.doc");
Response.ContentType = "application/ms-word";
}
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8; //关闭控件的视图状态
source.Page.EnableViewState =false; //初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
source.RenderControl(htmlWriter); //输出
Response.Write(writer.ToString());
Response.End();
} //文档类型
public enum DocumentType
{
Word,
Excel
}