Export DataTable to Excel Without a Form
Private Function DataTableToExcel(ByRef dtData As DataTable, ByVal dataFilter As String, ByVal fileName As String) As Boolean
Private Function DataTableToExcel(ByRef dtData As DataTable, ByVal dataFilter As String, ByVal fileName As String) As Boolean
Dim gcGrid As New DevExpress.XtraGrid.GridControlEnd Function
Dim gvView As New DevExpress.XtraGrid.Views.Grid.GridView
Dim bV As DevExpress.XtraGrid.Views.Base.BaseView = gvView
gcGrid.BindingContext = New System.Windows.Forms.BindingContext
gcGrid.MainView = gvView
gvView.GridControl = gcGrid
gcGrid.ViewCollection.AddRange({bV})
gcGrid.DataSource = dtData
gcGrid.ForceInitialize()
gvView.PopulateColumns()
gvView.OptionsView.ColumnAutoWidth = True
gvView.OptionsPrint.AutoWidth = False
gvView.BestFitMaxRowCount = -1
gvView.BestFitColumns()
gvView.ActiveFilterString = "CustExists='Y'"
If fileName.EndsWith(".xlsx") Then
gcGrid.ExportToXlsx(fileName)
Else
gcGrid.ExportToXls(fileName)
End If
Return True
VB.NET - Export DataTable to Excel Without a Form
Reviewed by Unknown
on
7:25 PM
Rating:
No comments: