代码之家  ›  专栏  ›  技术社区  ›  Adrita Sharma

Aspose.Cells.CellsException-“您正在使用评估副本,并且打开的文件超出了限制”

  •  0
  • Adrita Sharma  · 技术社区  · 6 年前

    我创建了一个函数,它返回 datatable 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;
      }
    

    一切都很顺利。当我使函数异步时,它显示错误:

    打开了超过限制的文件

    我用的是有执照的阿司匹林。请帮忙

    2 回复  |  直到 6 年前
        1
  •  1
  •   Antoine V    6 年前

    您必须通过以下方式添加许可证 these methods

    Aspose.Cells尝试在以下位置查找许可证:

    Explicit path包含Aspose.Cells.dll的文件夹

    包含条目程序集(your.exe)的文件夹

    程序集中名为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);
    
        2
  •  1
  •   bommelding    6 年前

    在将其归咎于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; 因为它可以掩盖错误。