All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP实例:用PHP如何获取歌曲时间_[PHP教程]
用XML和XSL来生成动态页面_[XML教程]
用SQL,Server,Prompt提高开发能力_[SQL,Server教程]
实例解析:减少SQL日志大小的三个好方法_[SQL Server教程]
分析各种数据库优点,帮你做出准确选择_mssql学习_编程技术
.NET,2.0中的企业库异常处理块简述_[Asp.Net教程]
SQL,Server数据库性能优化_[SQL,Server教程]
新手入门:PHP网站开发中常见问题汇总_php资料_编程技术
phpWind中配制伪静态的步骤_[PHP教程]
FreeBSD5.3下安装Apache+PHP+MySQL+Tomcat_php资料_编程技术
Reading number is top 10 pictures
A beautiful girl to bud3
Look for from human art net, is good--3
A man's favorite things4
你的钱干净吗?
Ashlynn Brooke photograph of a group4
Startling Russian girl blind date scene1
Born After 90 Beijing sports university campus flower photos2
宝贝系列
Ashlynn Brooke photograph of a group1
Summer is most suitable for young people to travel in China6
Download software ranking
变速齿轮3.26
Unix video tutorial12
艳兽都市
Unix video tutorial18
C#程序员参考手册
jdk1.6 for windows
Red cliff
双旗镇刀客B
The king of fighters 97(Mobile phone games-apk)
Adobe Flash Player(IE) 10.0.32.18 浏览器专用的FLASH插件
归海一刀 published in(发表于) 2014/1/30 1:29:57 Edit(编辑)
TABLE导入到EXCEL_[Asp.Net教程]

TABLE导入到EXCEL_[Asp.Net教程]

TABLE导入到EXCEL_[Asp.Net教程]
前台代码:ExportExcel1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ExportExcel1.aspx.cs" Inherits="ExportExcel1" %>





导出数据到EXCEL


Table Example, constructed programmatically



GridLines="Both"
HorizontalAlign="Center"
Font-Name="Verdana"
Font-Size="8pt"
CellPadding=15
CellSpacing=0
Runat="server"/>





后台代码: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 {
TableRow r1 = new TableRow();
for (int i=0; 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;//取出当前系统日期时间
string dtt = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString();//取出系统日期
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();

}
}


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.