Saturday 2 June 2012

Convert Xml in to Excel


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.Xml.Xsl;

public partial class ExcelFromXML : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "application/vnd.ms-excel";
        Response.Charset = "";
        DataSet ds = new DataSet();
      
        ds.ReadXml(Server.MapPath("XML//XmlFileFromDataBaseData.xml"));
        XmlDataDocument xdd = new XmlDataDocument(ds);
        XslTransform xt = new XslTransform();
        xt.Load(Server.MapPath("EXCEL//XSLTFile.xls"));
        xt.Transform(xdd, null, Response.OutputStream);
        Response.End();
    }
}

No comments:

Post a Comment