Save Dataset As Excel File C#

Posted on
  1. Save Dataset As Excel File C#
  2. Excel Data File
Save text file as excel file

Save Dataset As Excel File C#

Code Block Imports Microsoft.Office.Interop Public Class Form1 Private Sub Button1Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Set up a DataSet Dim ds As New DataSet ds.Tables.Add( 'Table' ) ds.Tables(0).Columns.Add( 'Col1' ) ds.Tables(0).Columns.Add( 'Col2' ) ds.Tables(0).Rows.Add(1, 2) ds.Tables(0).Rows.Add(3, 4) ds.Tables(0).Rows.Add(5, 6) Try Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As Excel.Range 'On Error GoTo ErrHandler ' Start Excel and get Application object. OXL = New Excel.Application oXL.Visible = True ' Get a new workbook. OWB = oXL.Workbooks.Add oSheet = oWB.ActiveSheet '//Write Dataset to Excel Sheet Dim irow As Integer = 1 For Each dr As DataRow In ds.Tables(0).Rows irow += 1 Dim icol As Integer = 1 For Each c As String In dr.ItemArray icol += 1 'Determine cell to write oSheet.Cells(irow, icol).Value = c Next Next ' Make sure Excel is visible and give the user control ' of Microsoft Excel's lifetime. OXL.Visible = True oXL.UserControl = True ' Make sure you release object references. ORng = Nothing oSheet = Nothing oWB = Nothing oXL = Nothing Catch ex As Exception MsgBox(Err.Description, vbCritical, 'Error: ' & Err.Number) End Try End Sub End Class. Code Block Imports Microsoft.Office.Interop Public Class Form1 Private Sub Button1Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Set up a DataSet Dim ds As New DataSet ds.Tables.Add( 'Table' ) ds.Tables(0).Columns.Add( 'Col1' ) ds.Tables(0).Columns.Add( 'Col2' ) ds.Tables(0).Rows.Add(1, 2) ds.Tables(0).Rows.Add(3, 4) ds.Tables(0).Rows.Add(5, 6) Try Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As Excel.Range 'On Error GoTo ErrHandler ' Start Excel and get Application object. OXL = New Excel.Application oXL.Visible = True ' Get a new workbook.

Jan 23, 2018 - Download Free Software Popol Vuh Heart Of Glass Rar Download. Free file hosting download links for Arturia Oberheim SEM V v1 1 2 PC. Portable corel draw 9 rar shared files: Here you can download free portable. Music, software or any other files. Rava Montr al Diary POPOL VUH GARTEN. Download free software popol vuh heart of glass rar file. Jun 21, 2018 - Nineteen-sixty-four saw the first wave of Beatles cover albums. The earliest of these were released before the release of 'Can't Buy Me Love. Dizzy Gillespie - Copenhagen Concert (1959) 1.I Found a Million Dollar Baby 2.My Man 3.Oh! Lady Be Good 4.They Can't Take That Away from Me 5.

OWB = oXL.Workbooks.Add oSheet = oWB.ActiveSheet '//Write Dataset to Excel Sheet Dim irow As Integer = 1 For Each dr As DataRow In ds.Tables(0).Rows irow += 1 Dim icol As Integer = 1 For Each c As String In dr.ItemArray icol += 1 'Determine cell to write oSheet.Cells(irow, icol).Value = c Next Next ' Make sure Excel is visible and give the user control ' of Microsoft Excel's lifetime. OXL.Visible = True oXL.UserControl = True ' Make sure you release object references. ORng = Nothing oSheet = Nothing oWB = Nothing oXL = Nothing Catch ex As Exception MsgBox(Err.Description, vbCritical, 'Error: ' & Err.Number) End Try End Sub End Class. Hi, you can easily export (existing or new spreadsheet) with this component. Here is a sample VB.NET code how to export DataSet to existing Excel spreadsheet: ' Create new Excel file. Dim excelFile = New ExcelFile ' Load Excel file from XLS format.

Save

Excel Data File

Dataset

ExcelFile.LoadXls(filePath) ' Append each DataTable to a worksheet with the same name. For Each dataTable As DataTable In dataSet.Tables Dim worksheet = excelFile.Worksheets(dataTable.TableName) worksheet.InsertDataTable(dataTable, worksheet.Rows.Count, 0, False) Next ' Save Excel file to XLS format. I know i am about two years late Private Sub Button1Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Set up a DataSet Me.TblDatabaseTableAdapter.Fill(Me.RecordsDataSet.tblDatabase) Try Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As Excel.Range 'On Error GoTo ErrHandler ' Start Excel and get Application object. OXL = New Excel.Application oXL.Visible = True ' Get a new workbook. OWB = oXL.Workbooks.Add oSheet = oWB.ActiveSheet '//Write Dataset to Excel Sheet Dim coll As Integer = 1 Dim irow As Integer = 1 For Each dr As DataRow In RecordsDataSet.Tables(0).Rows irow += 1 Dim icol As Integer = 1 For Each c As String In dr.ItemArray icol += 1 'Determine cell to write oSheet.Cells(irow, icol).Value = c Next Next ' Make sure Excel is visible and give the user control ' of Microsoft Excel's lifetime. OXL.Visible = True oXL.UserControl = True ' Make sure you release object references.

ORng = Nothing oSheet = Nothing oWB = Nothing oXL = Nothing Catch ex As Exception MsgBox(Err.Description, vbCritical, 'Error: ' & Err.Number) End Try End Sub i have use your method and it work great the only problem is i cant get the column name/header.