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

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

我创建了一个函数 returns 从 workbookdatatable

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;
  }

运行 很好。当我使函数异步时,它显示错误:

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

我使用的是经过许可的 Aspose。请帮助

您必须通过 these methods

添加许可证 Aspose

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");

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

在将其归咎于 Aspose 之前,让我们修复异步方法。

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;            
}

请注意 dt 可以而且应该像这样本地化。
删除 private DataTable dt = null; 行,因为它可能会掩盖错误。

当这仍然出现错误时,我会再次查看 Aspose。