Monday, October 11, 2004

Writing an XML to Excel using XSL Transform

******This example shows how to write an XML to an excel file using XSLT*******

///******Write this code block on the page code behind file******///

//if outputting content to Webpage uncomment these 2 lines below.
// Response.ContentType = "application/vnd.ms-excel";
// Response.Charset = "";
DataSet ds = new DataSet();
ds.ReadXml( @"E:\Kannan\XMLtoExcel Sample APP\sampleXML.xml");
XmlDataDocument xdd = new XmlDataDocument(ds);
XslTransform xt = new XslTransform();
xt.Load(@"E:\Kannan\XMLtoExcel Sample APP\xslSheet.xsl");
FileStream fs = new FileStream("c:\\test1.xls",FileMode.Create);
using (fs)
{
xt.Transform(xdd, null, fs);
}

///**************************XSL Style sheet file code*************************///
//Copy the contents and save the file as .XSL


xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" >

xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">




































No comments: