Search code examples
c#asposeaspose-cells

Aspose Cells ExportDataTable CellsException


I am trying to read an excel file of size 263 KB, it includes 3 columns and 6998 rows of data, the first column is alphanumeric id Site ID ex: 'D7302', and the other 2 columns are latitude and longitude of type decimal,

            try
        {
            dataTable = worksheet.Cells.ExportDataTable(HeaderLineStartingRowNumber, 0, worksheet.Cells.MaxRow - HeaderLineStartingRowNumber + 1, worksheet.Cells.MaxColumn + 1, true);
        }
        catch (CellsException)
        {
            dataTable = worksheet.Cells.ExportDataTableAsString(HeaderLineStartingRowNumber, 0, worksheet.Cells.MaxRow - HeaderLineStartingRowNumber + 1, worksheet.Cells.MaxColumn + 1, true);
        }

this code always throws CellsException and exports data as string which truncates decimals and returns a string so instead of 28.125027778 it returns 28, when i reduced the file size to 100 rows it was exported successfully as expected so it must be a size issue, so are there size limitations for ExportDataTable , Thank you


Solution

  • We have tested your issue with the following sample code and it worked fine. We tested this issue with the most recent version i.e. 18.4 uploaded on NuGet. Please download the sample Excel file used inside the code and also see the screenshot that shows, data from worksheet has been exported to data table successfully.

    The code is exactly similar to yours with few changes so we do not find any error in your code. Therefore, if you are using the older version, you must use the most recent version.

    If your issue still occurs with the most recent version, then provide us your runnable sample code (preferably sample console application project) along with all the files used inside your code. We will execute your code at our end and try to replicate the issue and log it in our database for a fix in future releases. Thanks for your cooperation in this regard and have a good day.

    Sample Excel File used inside the Code - Download Link:

    Sample Code

    Workbook wb = new Workbook("sampleExportDataTable.xlsx");
    
    Worksheet worksheet = wb.Worksheets["Data"];
    
    int HeaderLineStartingRowNumber = 25;
    
    var dataTable = worksheet.Cells.ExportDataTable(HeaderLineStartingRowNumber, 0, worksheet.Cells.MaxDataRow - HeaderLineStartingRowNumber + 1, worksheet.Cells.MaxDataColumn + 1, true);
    

    Screenshot: Export Data Table using Aspose.Cells APIs

    Note: I am working as Developer Evangelist at Aspose