Skip to content

SyncfusionExamples/How-to-import-data-from-excel-to-MAUI-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

How to import data from excel to 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 ItemSource for the DataGrid.

View sample in GitHub

Take a moment to pursue this documentation, where you can find more about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid(SfDataGrid).

Conclusion

I hope you enjoyed learning about how to import data from excel to MAUI DataGrid.

You can refer to our .NET MAUI DataGrid's feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac or feedback portal. We are always happy to assist you!

About

This repository contains the examples about how to import data from excel to MAUI DataGrid

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages