Home » excel » c# – Aspose.Cells.CellsException – "You are using an evaluation copy and have opened files exceeding limitation"

c# – Aspose.Cells.CellsException – "You are using an evaluation copy and have opened files exceeding limitation"

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have created a function that returns a datatable from a workbook.

public async Task<DataTable> GetDataTableFromTabRowColumn(string sheetName, int startRow, int endRow, int startCol, int endCol)
  {
     var task = new Task(() =>
     {
        DataTable dt = new DataTable();
        Workbook wb = new Workbook(FilePath); // error line
        Worksheet worksheet = wb.Worksheets[sheetName];

        dt = worksheet.Cells.ExportDataTable(startRow - 1, startCol - 1, (endRow - startRow + 1), (endCol - startCol + 1), options);
     });

     task.Start();
     await task;

     return dt;
  }

It was running fine. When I made the function async, it’s showing error:

Aspose.Cells.CellsException: ‘You are using an evaluation copy and
have opened files exceeding limitation.’

I am using licensed Aspose. Please help

How to&Answers:

You must add the licence Aspose by these methods

Aspose.Cells tries to find the license in the following locations:

Explicit path The folder that contains Aspose.Cells.dll

The folder that contains the assembly that called Aspose.Cells.dll

The folderthat contains the entry assembly (your .exe)

An embedded resource inthe assembly that called Aspose.Cells.dll

//Instantiate an instance of license and set the license file through its path
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense("Aspose.Cells.lic");

or

//Instantiate an instance of license and set the license through a stream
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(myStream);

Answer:

Before blaming it on Aspose, lets fix the async approach.

public async Task<DataTable> GetDataTableFromTabRowColumn(string sheetName, int startRow, int endRow, int startCol, int endCol)
{                  
    var task = Task.Run(() =>
    {            
        Workbook wb = new Workbook(FilePath); // error line
        Worksheet worksheet = wb.Worksheets[sheetName];

        DataTable dt = worksheet.Cells.ExportDataTable(startRow - 1, startCol - 1, (endRow - startRow + 1), (endCol - startCol + 1), options);

        return dt;
    });

    return await task;            
}

Note that dt can and should be local like this.
Remove the private DataTable dt = null; line because it could cover up an error.

When this still gives an error I would look at Aspsose again.