[学习公共库]导出数据到Excel |
麦林 发表于 2007/8/17 15:43:46 | 部分代码: Excel.Application excel = new Excel.ApplicationClass(); excel.Application.Workbooks.Add(true); excel.Visible = true; ConnectionString = "server = local;database = webSite;uid = sa;pwd = 123"; SqlConnection con = new SqlConnection(ConnectionString); SqlCommand cmd = new SqlCommand("select * from table",con); SqlDataReader read = cmd.ExecuteReader(); int row = 2, col; for (col = 0; col < read.FieldCount; col++) { excel.Cells[1, col + 1] = read.GetName(col); } while (read.Read()) { for (col = 0; col < read.FieldCount; col++) { excel.Cells[row, col + 1] = read.GetValue(col).ToString(); row++; } } excel.Visible = true;
|
|
|

.: 公告
|
« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
|
.: 我的分类(专题)
|

.: 最新日志
.: 最新回复
|

blog名称:栗色?蓝色? 日志总数:449 评论数量:201 留言数量:37 访问次数:2260232 建立时间:2006年5月16日 |
|

.: 留言板
|

.: 链接
|

|