1,使用exec master.dbo.xp_cmdshell 'bcp "select top 100 * from product order by id desc" queryout "d:\xx.csv" -w -S. -Usa -Psa' 2,使用DFVV8((忽然发现,俩裤衩了,向三只裤衩前进!)) 的方法, 3,使用winform的office类库生成
在程序里生成需要用office类库
exec master.dbo.xp_cmdshell 'bcp "select top 100 * from product order by id desc" queryout "d:\xx.csv" -w -S. -Usa -Psa'
obj.Response.Clear();
obj.Response.Buffer = true;
//obj.Response.Charset="GB2312";
obj.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8) + ".xls");
obj.Response.ContentEncoding = System.Text.Encoding.UTF8;//设置输出流为简体中文
obj.Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
obj.Response.ContentType = "application/vnd.ms-excel";
//System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
dg.RenderControl(htw); obj.Response.Write(sw.ToString());
obj.Response.End();
2,使用DFVV8((忽然发现,俩裤衩了,向三只裤衩前进!)) 的方法,
3,使用winform的office类库生成