A Blazor component and utility library for mapping uploaded CSV or tabular files to C# objects. Supports header extraction and user-defined property mapping.
$ dotnet add package Soenneker.Blazor.SheetMapperA Blazor component and utility library for mapping CSV or tabular files to C# objects.
Leverage FilePond for uploads and TomSelect for interactive dropdowns. Automatically extract headers, map columns to your model, and retrieve a clean { property → column } map.
Dictionary<string, string>dotnet add package Soenneker.Blazor.SheetMapper
Register interop in your DI container (e.g., Program.cs):
builder.Services.AddSheetMapperAsScoped();
Import namespace in your _Imports.razor or component:
@using Soenneker.Blazor.SheetMapper
@page "/import"
@inject ISheetMapperInterop SheetMapperInterop
<SheetMapper
@ref="sheetMapper"
TargetType="typeof(Employee)"
AutomaticallyMap="true"
ShowStatusIcons="true" />
<button class="btn btn-primary mt-3" @onclick="ShowMap">
Get Mapping
</button>
@code {
private SheetMapper? sheetMapper;
private void ShowMap()
{
if (sheetMapper is not null)
{
var map = sheetMapper.GetCurrentMap();
// map: property → CSV column
}
}
}
| Parameter | Type | Default | Description |
|---|---|---|---|
TargetType | Type | — | Required. Model type whose writable properties are mapped. |
AutomaticallyMap | bool | false | Run auto-mapping heuristic on file load. |
ShowStatusIcons | bool | true | Toggle visibility of the status‑icon column. |
NotMappedIcon | RenderFragment | ⚠️ | Icon/markup for unmapped state. |
DuplicatedIcon | RenderFragment | 🔁 | Icon/markup for duplicate‑mapping state. |
MappedIcon | RenderFragment | ✅ | Icon/markup for successful mapping. |
void AutoMap()
Re-run the auto-mapping logic at any time.
Dictionary<string, string> GetCurrentMap()
Returns { property → selected column }. Unmapped properties return "".
Override the built-in emojis with your own markup (SVG, <i>, etc.):
<SheetMapper
TargetType="typeof(Employee)"
NotMappedIcon="@<i class='fas fa-exclamation-triangle'></i>"
DuplicatedIcon="@<i class='fas fa-sync-alt'></i>"
MappedIcon="@<i class='fas fa-check-circle'></i>"
/>
Use the ShowStatusIcons parameter to toggle the entire status‑icon column:
<!-- hides the icons -->
<SheetMapper TargetType="typeof(Employee)" ShowStatusIcons="false" />
CSS classes for fine‑tuning:
.map-row — wrapper for each mapping row.status-icon — container for the iconOverride or extend them to match your design system.