.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

export to excel using xml to xslt

Posted By:Maverick       Posted Date: March 24, 2011    Points: 40    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

export to excel using xml to xslt. The excel file will be generated. The following is code to create the worksheet
 

Create an export to excel using xslt to xml to excel.

Step 1

Create a static data table with Account Name, Account Number, Amount, City, and State

 

Step 2

Place the following function and call it. The excel file will be generated. The following is code to create the worksheet.

The <%= sbTransactiongenerator.tostring()%> holds the entire string to be expoted as excel.

I have pasted the whole function here.


 

Private Sub ExportToExcel(ByVal ids As String)
        Dim MainCell As String = "{0}{1}{2}{3}{4}{5}"
        Dim dtExport As New DataTable
       
        Dim sbTransactionGenerator As New StringBuilder(50000)

        For i As Integer = 0 To dtExport.Rows.Count - 1
            sbTransactionGenerator.Append(String.Format(MainCell, dtExport.Rows(i).Item("AccountName").ToString(), dtExport.Rows(i).Item("AccountNumber").ToString(), dtExport.Rows(i).Item("Amount").ToString(), dtExport.Rows(i).Item("AccountHolderRegisteredCity").ToString(), "", dtExport.Rows(i).Item("InvoiceNumber").ToString()))
        Next


        Dim sheet = 
                    
                    
                        
                            <%= Session("AuthorName") %>
                            <%= Now %>
                            Ezend
                        
                        
                            12240
                            24855
                            240
                            105
                            False
                            False
                        
                        
                            
                            
                            
                            
                            
                            
                            
                            
                        
                        
                            
                                
                                
                                
                                
                                
                                
                                    
                                        AccountName
                                    
                                    
                                        AccountNumber
                                    
                                    
                                        Amount
                                    
                                    
                                        AccountHolderRegisteredCity
                                    
                                    
                                        
                                    
                                    
                                        Description
                                    
                                
                                <%= sbTransactionGenerator.ToString() %>
                            
600 0 False False
False False
False False Response.AppendHeader("Content-Disposition", "attachment; filename=" & strFileName & DateTime.Now.Ticks & ".xml") Context.Response.Write("") Context.Response.Write(sheet.ToString().Replace(">", ">").Replace("<", "<")) Context.Response.End() End Sub


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend