Click here to Skip to main content
15,892,537 members
Articles / Web Development / ASP.NET

Excel Export Component Using XSL

Rate me:
Please Sign up or sign in to vote.
4.55/5 (34 votes)
22 Oct 2006CPOL3 min read 375.8K   12.2K   165  
This is an article on an Excel export component (using XSL and XML) in .NET.

Partial Class Example1
    Inherits System.Web.UI.Page

    Dim objExport As ExportToExcel.ExcelExport

    Protected Sub cmdExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdExport.Click
        Dim strSql As String
        Dim strCon As String
        Dim strExcelFile As String
        Dim dsOrders As DataSet

        Try

            strSql = "select ord.orderid,ord.EmployeeID, ordDet.ProductID, ordDet.UnitPrice, ordDet.Quantity, "
            strSql = strSql & " ordDet.Discount from orders ord inner join ""order details"" ordDet "
            strSql = strSql & "on ord.orderid = ordDet.orderid where customerID = 'ALFKI' order by ord.orderid"

            strCon = System.Configuration.ConfigurationManager.AppSettings("ConStr")

            dsOrders = SqlHelper.ExecuteDataset(strCon, CommandType.Text, strSql)

            strExcelFile = objExport.TransformDataTableToExcel(dsOrders.Tables(0), True)

            objExport.SendExcelToClient(strExcelFile)

        Catch ex As Threading.ThreadAbortException
            'Do nothing
        Catch ex As Exception
            Response.Write(ex.ToString)
        End Try



    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        objExport = New ExportToExcel.ExcelExport

        objExport.TempFolder = "\Excel\Temp\"
        objExport.TemplateFolder = "\Excel\Template\"
        objExport.XSLStyleSheetFolder = "\Excel\XSLStyleSheet\"

        objExport.CleanUpTemporaryFiles()
    End Sub
End Class



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions