title: Reading Excel File in Blazor wasm using NPOI
body: <p>The following code works fine from a .NET Core app running on a PC. The code loads an excel file and reads it using the NPOI library.</p>
  <pre><code>public void ReadExcel()
          {
              DataTable dtTable = new DataTable();
              List&lt;string&gt; rowList = new List&lt;string&gt;();
              ISheet sheet;
              using (var stream = new FileStream(&quot;Test.xlsx&quot;, FileMode.Open))
              {
                  stream.Position = 0;
                  XSSFWorkbook xssWorkbook = new XSSFWorkbook(stream);
                  sheet = xssWorkbook.GetSheetAt(0);
                  IRow headerRow = sheet.GetRow(0);
                  int cellCount = headerRow.LastCellNum;
                  for (int j = 0; j &lt; cellCount; j++)
                  {
                      ICell cell = headerRow.GetCell(j);
                      if (cell == null || string.IsNullOrWhiteSpace(cell.ToString())) continue;
                      {
                          dtTable.Columns.Add(cell.ToString());
                      }
                  }
                  for (int i = (sheet.FirstRowNum + 1); i &lt;= sheet.LastRowNum; i++)
                  {
                      IRow row = sheet.GetRow(i);
                      if (row == null) continue;
                      if (row.Cells.All(d =&gt; d.CellType == CellType.Blank)) continue;
                      for (int j = row.FirstCellNum; j &lt; cellCount; j++)
                      {
                          if (row.GetCell(j) != null)
                          {
                              if (!string.IsNullOrEmpty(row.GetCell(j).ToString()) &amp;&amp; !string.IsNullOrWhiteSpace(row.GetCell(j).ToString()))
                              {
                                  rowList.Add(row.GetCell(j).ToString());
                              }
                          }
                      }
                      if (rowList.Count &gt; 0)
                          dtTable.Rows.Add(rowList.ToArray());
                      rowList.Clear();
                  }
              }
              return JsonConvert.SerializeObject(dtTable);
          }
  </code></pre>
  <p>I want to use this code in my Blazor app to be able to read an Excel file from a browser. I can use the InputFile component to get the file:</p>
  <pre><code>&lt;InputFile OnChange=&quot;GetFile&quot;/&gt;
  </code></pre>
  <p>The question is how to get the the uploaded file as a stream that I can pass to the ReadExcel function? So it should be something like this:</p>
  <pre><code>public async Task GetFile(InputFileChangeEventArgs e) //get excel file
      {
          
          stream = e.File.OpenReadStream(); //need a stream here that ReadExcel() can use!
                 
          ReadExcel();
      }
  </code></pre>
  <p>If I use the above stream in the ReadExcel function instead of the one it has, the code doesnt work. What is the correct way of forming this stream so that ReadExcel can use that instead of the one it has now?</p>
  <p>Thanks,
  Amjad.</p>