1

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

Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
  • The exception mentions clearly the problem , you're using trial version – Antoine V Jan 02 '19 at 10:00
  • 1
    No.. We are using licensed version – Adrita Sharma Jan 02 '19 at 10:01
  • 1
    I have a hard time believing that this is your exact (real) code because this code tries to return **`dt`** from a scope where it does not exist. – Peter B Jan 02 '19 at 10:08
  • 2
    It does sound a little like a fault in their license checking. But it's hard to be sure, like @peterB notes this is bad pseudo code. Contact the aspose helpdesk first and when you wan to ask here, post 2 minimal but _correct_ samples of working an not-working. – bommelding Jan 02 '19 at 10:16
  • Ya.. That will be a issue. As I mentioned. I have just added the code within the task. The original one had only 4 lines (currently within the task) and returned dt. Since it's breaking before returning anything. I didn't figure out that issue – Adrita Sharma Jan 02 '19 at 10:17
  • 1
    Well, This function was present in the application. My task was just to convert it to async which I have failed clearly. dt is initialized to null above all the functions.So there was no compile time error `private DataTable dt = null;` Can you guide me the right way to implement async – Adrita Sharma Jan 02 '19 at 10:47

2 Answers2

2

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);
Antoine V
  • 6,998
  • 2
  • 11
  • 34
2

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.

bommelding
  • 2,969
  • 9
  • 14
  • Thanks a lot.. I have implemented it. In aspose license file, there is a line Limited to 10 developers May be the issue came because of that.. – Adrita Sharma Jan 02 '19 at 11:35
  • That would not explain the difference with non-async. Unless the async version is used to process more data in parallel. – bommelding Jan 02 '19 at 11:43
  • 2
    I guess may be your licensing code is not processed at all, see the document on how to apply license for your reference: https://docs.aspose.com/display/cellsnet/licensing Please make sure your licensing code is processed first and at least once in the whole application life cycle. PS. I am working as Support developer/ Evangelist at Aspose. – Amjad Sahi Jan 03 '19 at 08:27