导出到数据到Excel的问题

wd_318 2003-06-28 08:08:57
我通过下面循环将数据倒出到EXCEL中:

for(row=0; row<rowcount ;row++)
{
for(int i=0;i<fieldcount;i++)
{
excel.Cells[row+2,i+1]=MyTable[row][i].ToString();
}
}
可是出现了下面问题:
1、数据太慢了,1000条记录就要花了4分钟!
2、“00002”这样的字段就会转换成数值型的“2”了!
3、“5-4”这样的字段会转变成:“5月4日”

请大家指点一下!有没办法解决?
如果 直接用SQL语句导出到EXCEL的方法更好!
...全文
17 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wd_318 2003-07-01
  • 打赏
  • 举报
回复
李大侠,我看过你的很多文章!景仰得很!
我在企业管理器中执行下面这句:
EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout C:\authors.xls -c -Sservername -Usa -P'
输出为:
row1:SQLState = 08001, NativeError = 17
row2:Error = [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server 不存在或访问被拒绝
ROW3:SQLState = 01000, NativeError = 53
ROW4:Warning = [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).
ROW5:<null>
lihonggen0 2003-06-30
  • 打赏
  • 举报
回复
http://www.csdn.net/develop/read_article.asp?id=18623
SmallCase 2003-06-30
  • 打赏
  • 举报
回复
强烈关注
wd_318 2003-06-28
  • 打赏
  • 举报
回复
UP
wd_318 2003-06-28
  • 打赏
  • 举报
回复
晕倒忘了注明:windows FORM
luckyyang 2003-06-28
  • 打赏
  • 举报
回复
直接导出
this.Page.Response.AddHeader("Content-Disposition", "attachment; filename=Client.xls");
this.Page.Response.Charset = "GB2312";
this.Page.Response.ContentEncoding =System.Text.Encoding.Default;
this.Page.Response.ContentType = "application/vnd.ms-excel";
System.IO.StringWriter textstring = new System.IO.StringWriter();
HtmlTextWriter htmltext = new HtmlTextWriter(textstring);
this.DataGrid1.RenderControl(htmltext);
this.Page.Response.Write(textstring);
this.Page.Response.End();

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧