Articles in this section

How to import data from excel to .NET MAUI DataGrid?

To import data from an Excel file into a .NET MAUI DataGrid, you can use the XlsIO library to read data from Excel files and then bind the data to the SfDataGrid in your MAUI application.

Install the Syncfusion.Maui.DataGridExport NuGet package to use the SfDataGrid and for reading Excel files.

C#

Place the Excel document in the Raw folder within the Resources directory. We can access the document using FileSystem.OpenAppPackageFileAsync().

private async Task LoadDataGridAsync()
{
    //Creates a new instance for ExcelEngine
    ExcelEngine excelEngine = new ExcelEngine();

    //Initialize IApplication
    Syncfusion.XlsIO.IApplication application = excelEngine.Excel;

    //Load the file into stream
    Stream inputStream = await FileSystem.OpenAppPackageFileAsync("DataGrid.xlsx");

    //Loads or open an existing workbook through Open method of IWorkbooks
    IWorkbook workbook = application.Workbooks.Open(inputStream);

    IWorksheet worksheet = workbook.Worksheets[0];

    DataTable customersTable = worksheet.ExportDataTable(1, 1, 20, 15, ExcelExportDataTableOptions.ColumnNames);

    this.dataGrid.ItemsSource = customersTable;

    workbook.Close();

    excelEngine.Dispose();
}

Read the content from the Excel sheet and export it to a DataTable. Then, assign the DataTable as the ItemsSource for the DataGrid.

Download the complete sample from GitHub

Conclusion

I hope you enjoyed learning how to import data from Excel into .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied