如何将数据从数据库导出到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 ();
}