Excel as data source

sblb 1,231 Reputation points
2023-01-12T11:56:07.4133333+00:00

Hi, I want to use the Excel file as data source to populate the table

I used the package EPPlus.

I received the message :

OfficeOpenXml.LicenseException: Please set the ExcelPackage.LicenseContext property

In my service I've put :

ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

I don't understand why I received the message to set the package because I used Noncommercial package.

Have you an idea? or have you other open source and free to read excel file and populate in table?

Thanks in advance

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,651 questions
{count} votes

Accepted answer
  1. Chen Li - MSFT 1,221 Reputation points
    2023-01-16T09:40:16.81+00:00

    Hi @sblb ,

    I finally found out where the problem was.

    In this code your tbody has wrong tag:

    <tboby>
         @foreach(DataRow row in dt.Rows)
         {
             <tr>
                @foreach(DataColumn col in dt.Columns)
                {
                     <td>@row[col.ColumnName].ToString()</td>
                }
             </tr>
          }
    </tboby>
    

    Changing <tboby></tboby> to <tbody></tbody> fixes this.

    In addition, the null reference exception you had before was caused by a for loop exception.

    for(var j=0; j <= cc; j++)
    {
        ICell cell = hr.GetCell(j);
        dt.Columns.Add(cell.ToString());
    }
    

    j cannot be equal to cc, this would go out of the scope of the loop. It should be:

    for(var j=0; j < cc; j++)
    

    You can have a try.


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Chen Li

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.