Review: SoftArtisans OfficeWriter v3
page 5 of 9
by Jesudas Chinnathampi (Das)
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 36759/ 46

Creating an Excel File Based on a Template

Using the ExcelWriter, it just takes the following lines of code, in VB.NET, to create an Excel file based on a template.

Dim oExcelTemplate As New ExcelTemplate
Dim myRdr As SqlDataReader
Dim ConnStr As String = ConfigurationSettings.AppSettings("ConnectionString")
Dim myConnection As SqlConnection = New SqlConnection(ConnStr)
Dim myCommand As SqlCommand = New SqlCommand("sp_authors_sel", myConnection)
Dim myAdapter As New SqlDataAdapter(myCommand)
Dim AuthDt As New DataTable
myAdapter.Fill(AuthDt)
oExcelTemplate.Open("c:\inetpub\wwwroot\writer\Excel\auth_template.xls")
oExcelTemplate.SetDataSource(AuthDt, "authors")
oExcelTemplate.Process()
oExcelTemplate.Save("c:\inetpub\wwwroot\writer\Excel\auth_output.xls")

It took me around 15 minutes to write the above code. This included creating the stored procedure, sp_authors_sel, which simply dumps all rows from the author table under the pubs database in SQL Server 2000, and creating the template file shown in Figure 1.

All we are doing here is executing a stored procedure and creating a new Excel file based on the template, auth_template.xls. The file path in the above example can also be a virtual path rather than a physical path. Instead of saving the new file in the server, you could also stream the output as an HTTP response to the client machine.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 9:56:22 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search