Search code examples
excelexcel-2007asposeaspose-cells

Cannot Retrieve Data from Excel File Created using Aspose.Cells


I create an Excel file (.xlsx) using the Aspose.Cells library. But I'm not able to read the data (retrieve rows) using OleDb commands after that, until I open the file and save it manually. I'm running something as simple as this one:

new OleDbDataAdapter("select * from [Sheet1$]", conn); // etc...

Saving the file increases the size of the file as well. Please note that this happens only with the .xlsx format, for the old .xls everything works fine. I even tried the demo code that they have on their website, but the result is the same. Am I missing something?


Solution

  • It seems you need to set the ExportCellName name property to true before saving to xlsx/xlsm format.

    Please see the following sample.

    //Create your workbook
    Workbook workbook = new Workbook(filePath);
    
    //Do your processing
    
    //Save your workbook with export cell as true
    OoxmlSaveOptions opts = new OoxmlSaveOptions();
    opts.ExportCellName = true;
    workbook.Save("output.xlsx", opts);
    

    Note: I am working as Developer Evangelist at Aspose