Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 26th, 2008, 12:19 PM
Registered User
Join Date: Aug 2008
Location: huntingdon valley, Pennsylvania, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel reports in vb.net

I am in need of pulling data from Access and dumping the data into Excel and formatting into a useable report.
I have a front end where the user would choose certain criteria to generate a query which will be sent to the database.
The returned recordset gets sent to a spreadsheet which I will then format to suit.

I need help properly sending the query and returning the data. Thanks!!!

Reply With Quote
  #2 (permalink)  
Old March 3rd, 2014, 03:53 AM
Registered User
Points: 21, Level: 1
Points: 21, Level: 1 Points: 21, Level: 1 Points: 21, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Feb 2014
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: Excel reports in vb.net

Hi, you can try the following VB.NET code.
Note you need to fill in TODO's: DB connection string and SQL query.
        Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\...\TODO.accdb"
        Dim results As New DataTable("Report")

        ' Retrieve Access DB data and fill DataTable.
        Using conn As New OleDbConnection(connString)
            Dim cmd As New OleDbCommand("SELECT * FROM TODO WHERE TODO", conn)
            Dim adapter As New OleDbDataAdapter(cmd)
        End Using

        ' Create new Excel report.
        Dim report As New ExcelFile()
        Dim reportSheet As ExcelWorksheet = report.Worksheets.Add(results.TableName)

        ' Insert DataTable to Excel sheet.
        Dim options As New InsertDataTableOptions("A1")
        options.ColumnHeaders = True
        reportSheet.InsertDataTable(results, options)

        ' Format header row.
        Dim headerFont As ExcelFont = reportSheet.Rows(0).Style.Font
        headerFont.Weight = ExcelFont.BoldWeight
        headerFont.Size = CInt(LengthUnitConverter.Convert(14, LengthUnit.Point, LengthUnit.Twip))

        ' AutoFit filled columns.
        Dim columnCount As Integer = reportSheet.CalculateMaxUsedColumns()
        For i As Integer = 0 To columnCount - 1

        ' Save Excel file.
I hope this can get anyone to start coding the similar requirements. Also you will notice that I used this VB.NET Excel component to generate a "Report.xls" file. It has great performances and it does not use excel automation, so it is quite suited for tasks like generating large reports.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 1.1,VB.NET,crystal reports, SQl server gvi Crystal Reports 1 September 11th, 2008 02:55 AM
Crystal Reports 11 from VB to VB.net koushik_b2002 Crystal Reports 2 June 1st, 2008 01:58 AM
Crystal reports and VB.NET minnug Crystal Reports 0 May 20th, 2007 10:09 PM
exporting crystal reports through vb.net nikks9 Crystal Reports 0 May 16th, 2006 04:16 AM
Crystal Reports in VB.Net PatMcM VB.NET 2002/2003 Basics 0 January 31st, 2006 03:37 AM

All times are GMT -4. The time now is 03:07 PM.

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