Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6233973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:23:58+00:00 2026-05-24T10:23:58+00:00

Aim to achieve : Want to dump a fetched table to a excel sheet.

  • 0

Aim to achieve :
Want to dump a fetched table to a excel sheet.

My implementation :

Imports System.Data.OleDb

    Private Sub getRawDataNextMonth()
    Dim sheetName As String = "RawData"
    Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\rawData.xlsx;Extended Properties=""Excel 12.0 XML;""")
    Dim adapter As New Data.OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$]", con)
    Dim dataSet As New Data.DataSet
    adapter.Fill(dataSet)
    Dim dataTable As Data.DataTable = dataSet.Tables(0)
    Dim rawData(dataTable.Rows.Count, dataTable.Columns.Count - 1) As Object
    Dim range As Excel.Range = WB.Sheets(sheetName).Range("A2:T" + dataTable.Rows.Count.ToString())
    For col = 0 To dataTable.Columns.Count - 1
        For row = 0 To dataTable.Rows.Count - 1
            rawData(row, col) = dataTable.Rows(row).ItemArray(col)
        Next
    Next
    range.Value2 = rawData
    End Sub

I am new to data fetching and ADO.Net concepts and just got it working.
But..

This seems to be very inefficient and lame to me.

So, can you help reducing the complexity and may be improve performance ?

A totally different (Better) implementation is most welcome !

Please help me optimize this… with your experience !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:23:58+00:00Added an answer on May 24, 2026 at 10:23 am

    This function writes out to a text file as CSV format and then opens the file in Excel and saves it as xlsx format. I tried this with a 53 column x 10,000 row table and it took ~2 seconds:

    Private Sub Export3(ByVal filename As String, ByRef dt As DataTable)
    
            Dim tempfile As String = Path.GetTempPath + Path.GetFileNameWithoutExtension(Path.GetTempFileName) + ".csv"
            Dim sb As StringBuilder
    
            Using sw As StreamWriter = New StreamWriter(tempfile)
                sb = New StringBuilder("")
                For c As Integer = 0 To dt.Columns.Count - 1
                    sb.Append(dt.Columns(c).ColumnName + ",")
                Next
                sw.WriteLine(sb.ToString.TrimEnd(","c))
    
                For r As Integer = 0 To dt.Rows.Count - 1
                    sb = New StringBuilder("")
                    For c As Integer = 0 To dt.Columns.Count - 1
                        sb.Append(dt.Rows(r).Item(c).ToString + ",")
                    Next
                    sw.WriteLine(sb.ToString.TrimEnd(","c))
                Next
            End Using
    
    
            Dim xlApp As Excel.Application = Nothing
            Dim xlBook As Excel.Workbook = Nothing
    
            Try
                xlApp = New Excel.Application
                'xlApp.Visible = True 'for debugging
                xlApp.DisplayAlerts = False
                xlBook = xlApp.Workbooks.Open(tempfile)
    
                xlBook.SaveAs(filename, Excel.XlFileFormat.xlWorkbookDefault)
    
                My.Computer.FileSystem.DeleteFile(tempfile)
    
            Finally
                If Not IsNothing(xlBook) Then
                    xlBook.Close()
                End If
                If Not IsNothing(xlApp) Then xlApp.Quit()
            End Try
        End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Aim to achieve : I want to change the source data for my pivot
Aim to achieve : I want to change the SourceData of the Pivot table.
Good day everybody, I'm beginner on C++. The aim I want to achieve is
Aim to Achieve : I want the Function to accept List(Of String), Array &
Aim To Achieve : I want to add the prevMonth's name at the end
Aim to Achieve : I want to have 3 different dataTables from 3 different
I am populating a template Excel sheet, with the data from the database :
I want a function ,when I choose myself defined layer,then the aim come out.such
My aim is to retrieve some data from a global array which is defined
My aim is to retrieve some data from a global array which is defined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.