日期:2014-05-20  浏览次数:20552 次

datagrid显示的数据导入到excel,该如何做
小妹刚学c#做应用程序,现在遇到一个问题,是把datagrid显示的数据导入到excel,该如何做,急

------解决方案--------------------
技术贴呀
用dataset 导入 excel的方法导
就是调用excel这个库 来做 网上有不少例子 你搜下
------解决方案--------------------
protected void ExportExcel(DataGrid dtgList, string strFileName) { DataTable dt = (DataTable)this.Session[ "GridToExcel "]; if (dt==null) return; Response.Clear(); Response.Buffer = true; Response.Charset = "gb2312 "; Response.AppendHeader( "Content-Disposition ", "online; filename= " + this.GetFileName(strFileName) + ".xls "); Response.ContentEncoding = System.Text.Encoding.GetEncoding( "gb2312 "); Response.ContentType = "application/ms-excel "; EnableViewState = false; System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo( "zh-CN ",true); System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); dtgList.AllowPaging = false; // dtgList.DataSource = dt; // dtgList.DataBind(); dtgList.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.Buffer = false; Response.End(); }
------解决方案--------------------
http://dotnet.aspx.cc/article/8a4cbf47-b888-4832-3389-ed3a3a3c8aab/read.aspx

------解决方案--------------------
介绍你一个组件:Aspose.Excel.dll,可以完成导入Excel,挺方便的。没几行代码!
------解决方案--------------------
http://blog.csdn.net/ChengKing/archive/2006/08/27/1128385.aspx
http://blog.csdn.net/ChengKing/archive/2006/08/10/1045853.aspx
http://blog.csdn.net/ChengKing/archive/2005/11/29/539514.aspx