如何将数据从数据库导出到EXCEL文件? [英] HOW TO EXPORT DATA FROM DATASET TO EXCEL FILE?

查看:156
本文介绍了如何将数据从数据库导出到EXCEL文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何将数据从数据集导出到excel文件吗?



Can any one tell me how to export data from dataset to excel file ?

string s = System.Configuration.ConfigurationSettings.AppSettings.Get("Conn");
            SqlConnection connection = new SqlConnection(s);
            connection.Open();
            SqlCommand cmd = new SqlCommand("ssp_AgriPrint");
            cmd.Parameters.AddWithValue("@cSerialNo", textBox1.Text);
            
            cmd.Connection = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter adapt = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();





I只想将数据集数据ds导出到excel文件



I just want to export dataset data ds to excel file

推荐答案

查看这些博客链接



1。 http://kishsharmasoftcode.blogspot.in/ [ ^ ]



2. http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data- to-excel-or.html [ ^ ]

如有任何疑问请发表评论。

welcome
Check with these blogs links

1.http://kishsharmasoftcode.blogspot.in/[^]

2.http://www.aspdotnet-suresh.com/2011/04/how-to-export-gridview-data-to-excel-or.html[^]
For any doubt please put comments.
welcome

HI,



请参考以下解决方案:



如何从c#中的数据集或数据表导出excel?



请在发布问题前使用谷歌...



谢谢


Refer the following solution:

How to export excel from dataset or datatable in c#?

Please use to google before posting the question...

Thanks


1)Import-export-dataset-xls。 [ ^ ]



2)Snippet来自 Export-dataset-to-excel-in-c [ ^ ]
public static void CreateWorkbook(DataSet ds, String path)
 {
    XmlDataDocument xmlDataDoc = new XmlDataDocument(ds);
    XslTransform xt = new XslTransform();
    StreamReader reader =new StreamReader(typeof (WorkbookEngine).Assembly.GetManifestResourceStream(typeof (WorkbookEngine), "Excel.xsl"));
    XmlTextReader xRdr = new XmlTextReader(reader);
    xt.Load(xRdr, null, null);

   StringWriter sw = new StringWriter();
    xt.Transform(xmlDataDoc, null, sw, null);

   StreamWriter myWriter = new StreamWriter (path + "\\Report.xls");
    myWriter.Write (sw.ToString());
    myWriter.Close ();
 }


这篇关于如何将数据从数据库导出到EXCEL文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆