导出到Excel时要引用的文件? 问题:导出到Excel的时候,要引用哪几个命名空间,还需要下载别的xxx.dll文件引用进去么?最好说详细一点,谢谢。引用自带的和自己下载引用的,这方面的原理我一点都不懂,都不知道怎么问大家,知道的稍微指点下,不知道也没关系,谢谢大家。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 命名空间是:using System.Drawing;using System.IO;using System.Text; //导出方法 private void Export(string FileType, string FileName) { Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.ContentType = FileType; this.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); GridView1.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); }调用方法: Export("application/ms-excel", "单据" + DateTime.Now.ToShortDateString() + ".xls"); gridview导出excel很简单打开excel模板,引用COM:Microsoft Excel 11.0 Object Library 这几天刚做了个.NET导出EXCEL的:http://blog.csdn.net/gdjlc/archive/2010/08/13/5810311.aspx 如果是gridview导出excel,下面程序即可:protected void btExcel_Click(object sender, EventArgs e) { Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = "gb2312"; Response.ContentEncoding = System.Text.Encoding.UTF7; //没有这一行,在Excel中的中文以乱码显示 Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); gvYearView.AllowPaging = false; BindgvYearView(0); gvYearView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); gvYearView.AllowPaging = true; BindgvYearView(0); } public override void VerifyRenderingInServerForm(Control control) //虽然该函数没有函数体,但只有重载此函数程序才能正常运行 { } 嗯,谢谢大家,我主要想知道的是引用COM里的哪几个文件,还需不需要引用自己下载的DLL。麻烦在告诉下,呵呵。 如果你要用Excel COM组件的话,需要添加对Excel com的引用。Add Reference...COM 页.找到Microsoft Excel 11.0 Object Library引用后就可以使用Microsoft.Office.Interop.Excel.ApplicationClass excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass(); 了 你想知道的是这个把 Microsoft.Office.Interop.Excel.dll 不需要下载DLL,但是需要机器上安装了Excel. 1装excel2,添加引用,选择com DataSet数据导出到Excel模板 简单问题 发生类型为 System.ArgumentException 的异常。 搜索无解,请帮忙 判断数组值为空的问题!!!!!!!!!! [求助]怎样利用存储过程批量导入多达23个字段的数据? 简单的框架传值问题! 怎样创建可以在客户端使用的ActiveX控件呀,举例说明。新手。 Asp.net 中取得登陆用户名的奇怪问题 数据分页问题 请教各位高手!!.asp页面html中编译能通过,但是运行有错误!!!! 动态改变CommandName gridview 页脚插入问题
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
调用方法: Export("application/ms-excel", "单据" + DateTime.Now.ToShortDateString() + ".xls");
打开excel模板,引用COM:Microsoft Excel 11.0 Object Library
protected void btExcel_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls"); Response.Charset = "gb2312";
Response.ContentEncoding = System.Text.Encoding.UTF7; //没有这一行,在Excel中的中文以乱码显示
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
gvYearView.AllowPaging = false;
BindgvYearView(0);
gvYearView.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); gvYearView.AllowPaging = true;
BindgvYearView(0);
}
public override void VerifyRenderingInServerForm(Control control) //虽然该函数没有函数体,但只有重载此函数程序才能正常运行
{ }
Add Reference...
COM 页.
找到Microsoft Excel 11.0 Object Library
引用后就可以使用
Microsoft.Office.Interop.Excel.ApplicationClass excelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
了
Microsoft.Office.Interop.Excel.dll
不需要下载DLL,但是需要机器上安装了Excel.
2,添加引用,选择com