How to export dataset data to excel in windows applications using C#?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Posted Sep 7, 2011, 5:05 AM EDT
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
srinivas P127 reputationPosted Sep 7, 2011, 11:05 PM EDT