Click here to Skip to main content
15,940,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im able to populate the dataset to a new excel sheet successfully.
But i need to export the data set to a predefined excel sheet(with formulas for certain fields)

Kindly advice...
Posted

 
Share this answer
 
try the following :


References and namespaces:
C#
using Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.InfoPath.Xml;
using System.Xml.Xsl;
using System.Xml;

XmlDataDocument xmlDoc = new System.Xml.XmlDataDocument(CVDtls);
XslCompiledTransform xslTran = new System.Xml.Xsl.XslCompiledTransform();

 //Create XmlTextWriter for the FileSteam
 //FileStream fs = new System.IO.FileStream("testing.xls",FileMode.OpenOrCreate);
 FileStream fs = new System.IO.FileStream(@"C:\EXPORTED\test.xls", FileMode.OpenOrCreate);
              
 XmlTextWriter xtw = new System.Xml.XmlTextWriter(fs, System.Text.Encoding.Unicode);

    //Add processing instructions to the beginning of the XML file,X
 // one of which indicates a style sheet.
 xtw.WriteProcessingInstruction("xml", "version='1.0'");
 string strXSLFilename;
strXSLFilename = "test.xsl";
 xtw.WriteProcessingInstruction("xml-stylesheet", "type='text/xls' href='" + strXSLFilename + "'");

 //Write the XML from the dataset to the file
CVDtls.WriteXml(xtw);
 xtw.Close();
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900