Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor WASM and ExcelDataReader are they compatible?

$
0
0

I need to read and parse Excel Spreadsheets in my Blazor application. Once I read the data I will persist it, but my main issue is that the Nuget package ExcelDataReader I am using throws an error when attempting to use which seems to indicate I cannot use it in a WASM application:

System.NotSupportedException: Specified method is not supported.   at Microsoft.AspNetCore.Components.Forms.BrowserFileStream.Seek(Int64 offset, SeekOrigin origin)   at ExcelDataReader.ExcelReaderFactory.CreateOpenXmlReader(Stream fileStream, ExcelReaderConfiguration configuration)   at CollectXScore.Web.ExcelFileReader.LoadFile(InputFileChangeEventArgs ev) in D:\Intellaegis\CollectXScore\CollectXScore.Web\ExcelFileReader.cs:line 54   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)   at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.PostAsync[TState](Task antecedent, Action`1 callback, TState state)

When doing the following:

public async void LoadFile(InputFileChangeEventArgs ev){    IReadOnlyList<IBrowserFile> files = ev.GetMultipleFiles();    foreach (IBrowserFile file in ev.GetMultipleFiles())    {        Debug.WriteLine(file.ContentType);        if (excelContentTypes.Contains(file.ContentType) || file.ContentType == "text/csv")        {            // Auto-detect format, supports:            //  - Binary Excel files (2.0-2003 format; *.xls)            //  - OpenXml Excel files (2007 format; *.xlsx, *.xlsb)            System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);            using (var reader = ExcelReaderFactory.CreateReader(file.OpenReadStream()))            {                // Use the AsDataSet extension method                // The result of each spreadsheet is in result.Tables                var result = reader.AsDataSet();                // Access data in the DataSet                var dataTable = result.Tables[0];                foreach (DataRow row in dataTable.Rows)                {                    foreach (var cell in row.ItemArray)                    {                        Debug.WriteLine(cell);                    }                }            }        }    }}

I have tried using a memory stream also without success.

Was expecting be able to read the Excel file contents. Instead got unsupported result.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>