How to export dataset data to excel in windows applications using C#?
how to export dataset data to excel in windows applications using c#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
srinivas PPosted Sep 8, 2011, 3:05 AM
Posted Sep 7, 2011, 9:05 AM
Please refer this code snippet.
DataSet ds; // dataset you want to export out to the file
//Create FileStream
XmlDataDocument xmlDoc = new System.Xml.XmlDataDocument(ds);
XslCompiledTransform xslTran = new System.Xml.Xsl.XslCompiledTransform();
//Create XmlTextWriter for the FileSteam
FileStream fs = new System.IO.FileStream(xmlFile, System.IO.FileMode.Create);
XmlTextWriter xtw = new System.Xml.XmlTextWriter(fs,System.Text.Encoding.Unicode);
//Add processing instructions to the beginning of the XML file,
// one of which indicates a style sheet.
xtw.WriteProcessingInstruction("xml","version='1.0'");
strXSLFilename = "test.xsl";
xtw.WriteProcessingInstruction("xml-stylesheet","type='text/xsl' href='" + xslRef + "'");
//Write the XML from the dataset to the file
ds.WriteXml(xtw);
xtw.Close();
http://forums.devx.com/showthread.php?t=158515
http://support.microsoft.com/kb/316934