TL;DR: Learn how to import Excel and CSV files into a .NET MAUI DataGrid using FilePicker, Syncfusion XlsIO, and a lightweight CSV parser. The imported data is converted into a DataTable and displayed in an interactive DataGrid with sorting, filtering, grouping, and editing.
Need to display data from Excel and CSV files directly in your .NET MAUI application? Instead of requiring users to open these files in separate applications, you can import them and display the data in a DataGrid, allowing users to work with it directly within your app.
In this blog, we’ll build an import process using the Syncfusion .NET MAUI DataGrid. We’ll use the .NET MAUI FilePicker to select files, Syncfusion XlsIO to read Excel data, and a CSV parser to process CSV files. Both formats will be converted into a DataTable and displayed in the DataGrid.
The import pipeline is simple:
Pick an Excel or CSV file → Process the data → Store it in a DataTable → Show it in the DataGrid
What we’ll build
The application will allow users to:
- Select an Excel or CSV file from their device.
- Read Excel data using Syncfusion XlsIO.
- Parse CSV data.
- Convert the imported data into a DataTable.
- Display the data in the Syncfusion DataGrid.
- View the number of imported rows and columns.
- Receive feedback when an import fails.
Once the data is displayed, you can configure the DataGrid to support features such as sorting, filtering, grouping, and editing.
Why import Excel and CSV data into a .NET MAUI DataGrid?
Excel and CSV files are convenient for storing and sharing tabular data. However, users may need more than a way to open these files. They may want to search, filter, sort, or edit the data directly within an application.
Importing the data into a DataGrid provides a way to work with it inside the app.
The key is to separate file processing from data display. First, read the file and prepare the data. Then, bind the resulting data to the DataGrid.
Let’s implement this process step by step.
Implement Excel and CSV import in a .NET MAUI DataGrid
Prerequisites
Before getting started, make sure your .NET MAUI project has the required workload installed.
Add the following NuGet packages:
Syncfusion’s .NET MAUI examples use XlsIO to read Excel files and export worksheet data to a DataTable, which can then be assigned to the DataGrid’s ItemsSource.
1. Create the data model
The imported data needs to be available to the UI so that the application can track changes to the data property.
Create a model that implements INotifyPropertyChanged:
public class Model : INotifyPropertyChanged
{
// Raised when a property value changes to notify bound UI elements.
public event PropertyChangedEventHandler? PropertyChanged;
}
In this example, the DataTable provides a common structure for both Excel and CSV data.
2. Create the ViewModel for file import
Next, we’ll handle file selection and data import.
The ViewModel will:
- Open the file picker.
- Determine whether the selected file is an Excel or CSV file.
- Read the file.
- Convert its contents into a DataTable.
- Return the imported data to the UI.
This keeps the file-import logic separate from the DataGrid display.
Import data from Excel
For Excel files, Syncfusion XlsIO reads the workbook and exports the worksheet data to a DataTable.
private static DataTable ImportFromExcel(Stream excelStream)
{
using var memory = new MemoryStream();
excelStream.CopyTo(memory);
memory.Position = 0;
using var excelEngine = new Syncfusion.XlsIO.ExcelEngine();
var xlsApp = excelEngine.Excel;
xlsApp.DefaultVersion = Syncfusion.XlsIO.ExcelVersion.Xlsx;
var workbook = xlsApp.Workbooks.Open(memory);
var sheet = workbook.Worksheets[0];
var dataTable = sheet.ExportDataTable(
sheet.UsedRange,
Syncfusion.XlsIO.ExcelExportDataTableOptions.ColumnNames);
// Remove completely empty rows.
for (int i = dataTable.Rows.Count - 1; i >= 0; i--)
{
bool empty = true;
foreach (var obj in dataTable.Rows[i].ItemArray)
{
if (obj is not null &&
obj is not DBNull &&
!(obj is string s && string.IsNullOrWhiteSpace(s)))
{
empty = false;
break;
}
}
if (empty)
{
dataTable.Rows.RemoveAt(i);
}
}
return dataTable;
}
The important part is ExportDataTable. It converts the worksheet’s used range into a tabular structure that can be used as the DataGrid’s data source. This is also the approach shown in Syncfusion’s documented Excel-to-MAUI-DataGrid example.
The code selects the first worksheet and treats its first exported row as the column names. It also removes completely empty rows before displaying the data.
Import data from CSV
CSV files do not require an Excel workbook. We can read them directly from the selected stream and convert their contents into a DataTable.
private static DataTable ImportFromCsv(Stream csvStream)
{
// CSV import implementation:
// 1. Read the CSV file from the provided stream.
// 2. Extract column headers from the first row.
// 3. Create DataTable columns based on the headers.
// 4. Read each subsequent row and populate the DataTable.
// 5. Return the populated DataTable.
}
Here, the first row is treated as the column header. The code also handles duplicate column names by generating unique names and fills missing cells with empty strings.
Note: The ParseCsvLine helper used in this implementation must be included in the complete sample repository.
3. Load the selected file
Now, we’ll connect the .NET MAUI FilePicker to the Excel and CSV import methods.
The .NET MAUI FilePicker allows users to select a file from their device. The following method configures the supported file types, opens the selected file as a stream, and calls the appropriate import method.
public async Task<DataTable?> ImportFromFilePickerAsync()
{
// Import data from the selected file and return it as a DataTable.
}
The import logic now has a clear responsibility:
- FilePicker selects the file.
- The file extension determines which import method to call.
- The selected method reads the file and returns a DataTable.
The DataGrid can use the same data structure regardless of whether the user selects an Excel or CSV file.
Note: This example supports .xlsx and .csv files. The Excel import reads the first worksheet, and the CSV import treats the first row as the column header.
4. Build the .NET MAUI DataGrid UI
With the import logic ready, let’s create a simple UI that lets users select a file and view the imported data.
The UI needs two primary elements:
- An Import from File button.
- A Syncfusion DataGrid to display the imported records.
<Grid Padding="16" RowSpacing="12">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Grid.Row="0"
WidthRequest="300"
HeightRequest="50"
Text="Import from File"
Clicked="OnImportClicked" />
<syncfusion:SfDataGrid Grid.Row="1"
x:Name="DataGrid"
ColumnWidthMode="Fill"
HeaderRowHeight="40"
RowHeight="40" />
</Grid>
The button starts the file-selection process, while the DataGrid displays the imported data.
Connect the import button to the DataGrid
Add the following event handler:
private async void OnImportClicked(object sender, EventArgs e)
{
try
{
var table = await _service.ImportFromFilePickerAsync();
if (table is null)
{
return;
}
DataGrid.Columns.Clear();
DataGrid.ItemsSource = table.DefaultView;
ViewModel.Items = table;
await DisplayAlertAsync(
"Success",
$"Imported {table.Rows.Count} rows and {table.Columns.Count} columns.",
"OK");
}
catch (Exception ex)
{
await DisplayAlertAsync(
"Import Failed",
ex.Message,
"OK");
}
}
The key line is:
DataGrid.ItemsSource = table.DefaultView;
This assigns the imported data to the DataGrid through the DataTable’s default view.
After a successful import, the application displays the number of imported rows and columns. If the user cancels file selection, the method returns without displaying a success message.
If an exception occurs during selection or processing, the application displays an error alert.
See the import flow in action
When you run the sample, the application displays an Import from File button.
Select an Excel or CSV file. The application reads the file, converts its contents into a DataTable, and assigns the result to the DataGrid. A success message displays the number of imported rows and columns.
The result is a DataGrid containing the imported data, ready for further interaction.
Handling the imported data
Once the data is displayed, you can extend the DataGrid configuration to support features based on your application’s requirements, including:
- Sorting.
- Filtering.
- Grouping.
- Editing.
- Custom column behavior.
- Data validation and application-specific processing.
Because both file formats are converted into a DataTable, the same data-binding approach can be used regardless of the original file format.
GitHub reference
You can explore the complete sample, including the file-import logic and DataGrid implementation, in the GitHub repository.
Frequently Asked Questions
What file formats are supported?
The sample supports Excel(.xlsx) and CSV(.csv) files. The file picker is configured to display these file types on the supported platforms.
To support additional formats, update the file-picker configuration and add the corresponding processing logic.
Which NuGet packages are required?
The sample uses: Syncfusion.Maui.DataGrid and Syncfusion.XlsIO.NETCore. The .NET MAUI workload is also required.
For Excel import, XlsIO provides the APIs used to open the workbook and export worksheet data to a DataTable.
How is the imported data bound to the DataGrid?
Both Excel and CSV data are converted into a DataTable. The resulting DataView is assigned to the DataGrid’s ItemsSource:
DataGrid.ItemsSource = table.DefaultView;
This provides a common data source for both file formats.
Does the import handle empty rows and duplicate headers?
For Excel files, the sample removes completely empty rows after exporting the worksheet data.
For CSV files, the import logic generates unique column names when duplicate headers are detected and fills missing cells with empty strings.
Can I use a strongly typed collection instead of a DataTable?
Yes. A DataTable is convenient when the column structure is determined by the imported file.
If your application has a known schema, you can map the imported rows to a model and bind an ObservableCollection<T> to the DataGrid instead.
How can I handle large files?
The DataGrid supports virtualization for larger datasets. However, the import process itself also affects performance.
For very large files, avoid unnecessary data copies and consider moving longer-running processing away from the UI thread so the application remains responsive.
The appropriate approach depends on the file size, data structure, and processing requirements of your application.
Try It Free
Conclusion
Importing Excel and CSV files into the Syncfusion .NET MAUI DataGrid provides a way to work with file-based data directly inside an application.
In this example, FilePicker handles file selection, Syncfusion XlsIO reads Excel data, a CSV parser processes CSV files, and both formats are converted into a DataTable before being displayed in the Syncfusion .NET MAUI DataGrid.
You can extend this approach with application-specific validation, data transformation, strongly typed models, and additional DataGrid features.
Explore the complete GitHub example to try importing your own Excel and CSV data into a .NET MAUI application.
For more information, refer to the Syncfusion .NET MAUI DataGrid documentation.
If you’re a Syncfusion customer, you can access the latest Essential Studio release from the license and downloads page. New users can try Syncfusion with a 30-day free trial.
For questions, contact us through our support forums, feedback portal, or support portal.
PakarPBN
A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.
In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.
The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.
