EXport data to Excel File

  • 12 years ago

    Hiiiiiiiiiiiiii,

    How to export data to excel.... currenctly for download 2000 rows i need until 8 minutes..

    How to fast export datas... the below is my current code for export data..

     

    daExcelExport = New System.Data.SqlClient.SqlDataAdapter(Str, MyConnection.open)

    daExcelExport.Fill(dsExcelExport)

    With Excel

    .SheetsInNewWorkbook = 1

    .Workbooks.Add()

    .Worksheets(1).Select()

    'For displaying the column name in the the excel file.

    Dim i As Integer = 1For col = 0 To dsExcelExport.Tables(0).Columns.Count - 1

    .cells(1, i).value = dsExcelExport.Tables(0).Columns(col).ColumnName

    .cells(1, i).EntireRow.Font.Bold = True

    .cells(1, i).EntireColumn.AutoFit()

    i += 1

    Next

    'For displaying the column value row-by-row in the the excel file.

    i = 2

    Dim k As Integer = 1For col = 0 To dsExcelExport.Tables(0).Columns.Count - 1

    i = 2

    For row = 0 To dsExcelExport.Tables(0).Rows.Count - 1

    .Cells(i, k).Value = dsExcelExport.Tables(0).Rows(row).ItemArray(col)

    .cells(i, k).EntireColumn.AutoFit()

    i += 1

    Next

    k += 1

    Next

    strExcelFile = F_SaveDialog.F_SaveDialog_Location & "\" & F_SaveDialog.F_SaveDialog_FileName & ".xls"

    .ActiveWorkbook().SaveAs(strExcelFile)

    .ActiveWorkbook.Close()

    End With

    Excel.Quit()

    Excel = Nothing

    GC.Collect()

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon