Skip to content

Commit b9a188a

Browse files
authored
Csv mapper delimiter (#195)
* Update for entire Google Font list as of 3/15/2023 * Add Csv Mapper Configuration for Delimiter
1 parent f110664 commit b9a188a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CodeBeam.MudBlazor.Extensions/Components/CsvMapper/MudCsvMapper.razor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using MudExtensions.Utilities;
88
using System.Globalization;
99
using System.Text;
10+
using CsvHelper.Configuration;
1011

1112
namespace MudExtensions
1213
{
@@ -103,6 +104,9 @@ public partial class MudCsvMapper : MudComponentBase
103104
[Parameter]
104105
public bool NormalizeHeaders { get; set; }
105106

107+
[Parameter]
108+
public string Delimter { get; set; } = ",";
109+
106110
[Inject] private IDialogService _dialogService { get; set; }
107111
[Inject] private NavigationManager _navigationManager { get; set; }
108112

@@ -169,7 +173,14 @@ private async Task ReadFile(IBrowserFile file)
169173
private void CreateCsvContent()
170174
{
171175
using var reader = new StreamReader(new MemoryStream(FileContentByte), Encoding.Default);
172-
using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
176+
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
177+
{
178+
Delimiter = Delimter,
179+
IgnoreBlankLines = true,
180+
HasHeaderRecord = true
181+
};
182+
183+
using var csv = new CsvReader(reader, config);
173184
CsvContent = csv.GetRecords<dynamic>().Select(x => (IDictionary<string, object>)x).ToList();
174185
}
175186
private void MatchCsvHeadersWithExpectedHeaders()

ComponentViewer.Docs/Pages/Examples/CsvMapperExample1.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<MudSwitch @bind-Checked="_customLocalization" Color="Color.Primary" Label="Custom Localization (German)" />
88
</MudItem>
99
<MudItem xs="12">
10-
<MudCsvMapper @ref="_csvMapper" Class="pa-4" AllowCreateExpectedHeaders="true" AutoMatch="AutoMatching.Partial" NormalizeHeaders="true" ShowIncludeUnmappedData="true" ExpectedHeaders="_expectedFields" OnImported="Upload" LocalizedStrings="GetLocalizedStrings()"></MudCsvMapper>
10+
<MudCsvMapper @ref="_csvMapper" Delimter="," Class="pa-4" AllowCreateExpectedHeaders="true" AutoMatch="AutoMatching.Partial" NormalizeHeaders="true" ShowIncludeUnmappedData="true" ExpectedHeaders="_expectedFields" OnImported="Upload" LocalizedStrings="GetLocalizedStrings()"></MudCsvMapper>
1111
</MudItem>
1212
</MudGrid>
1313

0 commit comments

Comments
 (0)