向高手请教 asp.net 中如何把数据库的数据写到excel 现成的模版上(模版列值是定死) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 论坛里有导出数据至excel的帖子,你可以搜索下 先将数据库中的数据保存在repert 上或着 gridview 上面 然后再导入到excel 中 /// <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 } 一个关于sql通配符问题 --- 关于用户控件的2个问题 谢谢各位 ---- 帮顶给分撒 C# 怎么定义一个变量,占内存10个字节 郁闷散分, crystal打印时出现一个小对话框 为什么得不到DropDownList的值? ??我在dataGrid中绑定了dropDownList控件,怎样把原来label的值设为dropDownList的默认项!! 麻烦各位给看看? 想请教各位高手,怎样实现类似C/S中的下拉菜单! 还是DataList的问题(高手请进) 截取字符串 dropdownlist问题
/// 将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
}