Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 2nd, 2006, 09:43 AM
Authorized User
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default .NET Tips-Simple way 2 Create Excel 4m DataTable

Here we will discuss a simple solution to create excel file from asp.net without excel software.

    Function CreateExcelFile(ByVal dt As DataTable) As Boolean
        Dim bFileCreated As Boolean = False
        Dim sTableStart As String = "<HTML><BODY><TABLE Border=1><TR><TH>Header1</TH></TR>"
        Dim sTableEnd As String = "</TABLE></BODY></HTML>"
        Dim sTableData As String
        Dim nRow As Long
        For nRow = 0 To dt.Rows.Count - 1
            sTableData &= "<TR><TD>" & dt.Rows(nRow).Item(0).ToString & "</TD></TR>"
        Dim sTable As String = sTableStart & sTableData & sTableEnd
        Dim oExcelFile As System.IO.File
        Dim oExcelWrite As System.IO.StreamWriter
        sExcelFile = "c:/excelfile.xls"
        oExcelWrite = oExcelFile.CreateText(sExcelFile)
        bFileCreated = True
        Return bFileCreated
    End Function


Similar Threads
Thread Thread Starter Forum Replies Last Post
exporting datatable to excel swati_joshi ASP.NET 1.0 and 1.1 Basics 1 July 10th, 2006 08:34 AM
Flushing datatable to an Excel file... livehed General .NET 0 January 13th, 2006 08:21 AM
How to create an Excel Range class using vb.net? zayasv General .NET 0 October 30th, 2005 10:21 AM
Use Rows from a DataTable to Create Columns In oth indigolion Classic ASP Professional 0 August 5th, 2005 12:44 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.