解析TABLE導(dǎo)入到EXCEL_.Net教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:解析ASP.NET頁面數(shù)據(jù)導(dǎo)出到Excel或WordprivatevoidbtnMIME_Click(objectsender,System.EventArgse) { BindData(); Response.ContentType=application/vnd.ms-Excel; Response.AddHeader(Content-Disposition,inline;filename= +HttpUtility.UrlEncode(下載文件.xls,Encoding.UTF8)); //如
前臺代碼:ExportExcel1.aspx| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportExcel1.aspx.cs" Inherits="ExportExcel1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>導(dǎo)出數(shù)據(jù)到EXCEL</title> </head> <body> <h3>Table Example, constructed programmatically</h3> <form id="Form1" runat=server> <asp:Table id="Table1" GridLines="Both" HorizontalAlign="Center" Font-Name="Verdana" Font-Size="8pt" CellPadding=15 CellSpacing=0 Runat="server"/> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="導(dǎo)出數(shù)據(jù)" /> </form> </body> </html> |
后臺代碼:ExportExcel1.aspx .cs
| using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; public partial class ExportExcel1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // Generate rows and cells. TableRow r = new TableRow(); TableCell c1 = new TableCell(); c1.ColumnSpan = 2; c1.Text = "test"; c1.HorizontalAlign = HorizontalAlign.Center; r.Cells.Add(c1); Table1.Rows.Add(r); int numrows = 3; int numcells = 2; for (int j=0; j<numrows; j++) { TableRow r1 = new TableRow(); for (int i=0; i<numcells; i++) { TableCell c = new TableCell(); c.Controls.Add(new LiteralControl("row " + j.ToString() + ", cell " + i.ToString())); r1.Cells.Add(c); } Table1.Rows.Add(r1); } } protected void Button1_Click(object sender, EventArgs e) { DateTime dt = System.DateTime.Now;//取出當(dāng)前系統(tǒng)日期時間 string dtt = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString();//取出系統(tǒng)日期 string filestr = "C:\\excel"; //filestr是文件的路徑 StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); Table1.RenderControl(htmlWriter); string file = filestr + "\\" + dtt + ".xls"; if (!Directory.Exists(filestr)) { Directory.CreateDirectory(filestr); } System.IO.StreamWriter sw = new StreamWriter(file); sw.Write(stringWriter.ToString()); sw.Close(); } } |
分享:解析簡單實用的DataGrid自定義分頁源程序首先新建一個名為article.aspx的文件,將以下內(nèi)容拷貝到article.aspx.cs中: usingSystem; usingSystem.Data; usingSystem.Configuration; usingSystem.Collections; usingSystem.Web; usingSystem.Web.Security; usingSystem.Web.UI; usingSystem.Web.UI.WebCo
相關(guān).Net教程:
- asp.net如何得到GRIDVIEW中某行某列值的方法
- .net SMTP發(fā)送Email實例(可帶附件)
- js實現(xiàn)廣告漂浮效果的小例子
- asp.net Repeater 數(shù)據(jù)綁定的具體實現(xiàn)
- Asp.Net 無刷新文件上傳并顯示進(jìn)度條的實現(xiàn)方法及思路
- Asp.net獲取客戶端IP常見代碼存在的偽造IP問題探討
- VS2010 水晶報表的使用方法
- ASP.NET中操作SQL數(shù)據(jù)庫(連接字符串的配置及獲取)
- asp.net頁面?zhèn)髦禍y試實例代碼
- DataGridView - DataGridViewCheckBoxCell的使用介紹
- asp.net中javascript的引用(直接引入和間接引入)
- 三層+存儲過程實現(xiàn)分頁示例代碼
.Net教程Rss訂閱編程教程搜索
.Net教程推薦
- 如何使用.Net C#開發(fā)批量ACCESS數(shù)據(jù)庫壓縮軟件
- 將非模態(tài)對話框顯示為模態(tài)對話框
- DataGrid表頭不動,表身動
- 水晶易表調(diào)用C#的WebService,返回數(shù)據(jù)集合的應(yīng)用分析
- 解析五種ADO.NET數(shù)據(jù)庫連接知識
- asp.net中生成縮略圖并添加版權(quán)
- ASP.Net常用功能整理--生成圖片的縮略圖
- 談如何使用 Lambda 表達(dá)式做抽象代表
- 用XML JSP實現(xiàn)網(wǎng)頁內(nèi)容動態(tài)顯示的方案
- “/”應(yīng)用程序中的服務(wù)器錯誤及解決方法
- 相關(guān)鏈接:
- 教程說明:
.Net教程-解析TABLE導(dǎo)入到EXCEL
。