I am uploading a CSV file and then converting it to a List with XlsIo in memory. The problem is that the List comes back with the correct amount of records but the record fields are all null, false or 0, depending on the type.
private void OnInputFileChange(InputFileChangeEventArgs e)
{
selectedFile = e.GetMultipleFiles();
Message = $"{selectedFile.Count} file selected";
StateHasChanged();
}
private async void OnSubmit()
{
var file = selectedFile.FirstOrDefault();
HttpResponseMessage response;
Stream stream = file.OpenReadStream();
MemoryStream ms = new MemoryStream();
await stream.CopyToAsync(ms);
stream.Close();
ms.Position = 0;
using (ExcelEngine excelEngine = new ExcelEngine())
{
try
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = excelEngine.Excel.Workbooks.Open(ms, ",");
IWorksheet worksheet = workbook.Worksheets[0];
List<Person> people = worksheet.ExportData<Person>(1, 1, 74, 9);
var count = people.Count();
response = await Http.PostAsJsonAsync<List<Person>>("api/people/batch", people);
Message = $"{response}: {selectedFile.Count} file uploaded";
StateHasChanged();
}
catch(Exception e)
{
Message = e.Message;
}
}
}
"Id","PhotoURI","FirstName","LastName","IsStudent","Gender","BirthDate","DateStarted","DateLastAttended","IsHoh","StudioId","LocationId","hohId","IsProspect","IsVendor","RankId","UniformTopSize","UniformBottomSize","BeltSize"
3,"","Dyana","Ablahad",true,"Female","Jul 1, 1998","Sep 14, 2020","Jan 27, 2021",true,1,1,3,false,false,,,,
4,"2-2AAB6FFE-686C-408B-A5C54ADA7EC5D41E.jpg","Christy","Addison",true,"Female","Jul 3, 1979","Sep 5, 2019","Nov 21, 2020",true,1,1,4,false,false,,,,
5,"3-05B0F0F6-12B8-4EB8-BA01DFBDEE2A6F1E.jpg","Josette","Anderson",true,"Female","Dec 18, 1972","Jul 2, 2019","Jan 26, 2021",true,1,1,5,false,false,,,,
6,"4-F3D30079-F41A-46AC-8AE30AE8FD7900EF.jpg","Luca","Andreola",true,"Male","Feb 22, 2012","Jul 1, 2019","Jan 27, 2021",true,1,1,6,false,false,,,,