Search code examples
sql-serverexcelvb.netdevexpress

Show Excel to Gridview in VB


I want to know how to Import from Excel to show on Gridview or VB, but I do not know how to do a previous view, only Exports, but it does not Import.

This is the code I use:

sql.Export_Excel(GridControl1, "Test" & TimeOfDay.Second & ".xls")

Import or Export:

enter image description here


Solution

  • Use DevExpress.DataAccess.Excel.ExcelDataSource.

    Your code should be something like this:

    Dim excelDS As New ExcelDataSource()
    excelDS.Name = "My Excel Data Source" 
    excelDS.FileName = "pathtoexcel.xlsx"
    Dim worksheet As New ExcelWorksheetSettings("DemoData", "A1:G50")
    excelDS.SourceOptions = New ExcelSourceOptions(worksheet)
    excelDS.Fill()
    gridControl.DataSource = excelDS