guys - most of the export to excel code i've found really doesn't wind up being excel. it's simply HTML w/ a .xls tag on it. and i've done this for years in, winforms in both c# & but it's always a hack. can someone point me in the direction of how to export a datatable to the real excel? like what reference i need to use how i build the headers and the info (data). i'm just not finding anything.

I don't think anyone has any idea what you are talking about. What is "real excel"? There are tons of examples on how to create excel files on the net. Present some code, or at least some pseudo code of what you are trying to do.

Edited 2 Years Ago by cgeier

i actually found something but you must use the : Microsoft.Office.Interop assembly.
so, this is what i'm talking about. thanks

Public Sub ExportToExcel(ByVal dtTemp As DataTable, ByVal filepath As String)
        Dim strFileName As String = filepath
      Dim _excel As New Excel.Application
        Dim wBook As Excel.Workbook
        Dim wSheet As Excel.Worksheet
        wBook = _excel.Workbooks.Add()
        wSheet = wBook.ActiveSheet()
        Dim dt As System.Data.DataTable = dtTemp
        Dim dc As System.Data.DataColumn
        Dim dr As System.Data.DataRow
        Dim colIndex As Integer = 0
        Dim rowIndex As Integer = 0
        For Each dc In dt.Columns
            colIndex = colIndex + 1
            wSheet.Cells(1, colIndex) = dc.ColumnName
        For Each dr In dt.Rows
            rowIndex = rowIndex + 1
            colIndex = 0
            For Each dc In dt.Columns
                colIndex = colIndex + 1
                wSheet.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
        MessageBox.Show("File Export Successfully!")
    End Sub
This article has been dead for over six months. Start a new discussion instead.