Issue with reading Excel file from stream

Posted by: iishchenko on 22 March 2022, 4:38 am EST

    • Post Options:
    • Link

    Posted 22 March 2022, 4:38 am EST


    m getting an issue with reading file from the stream and operating values in this file. When reading file from the stream, formatting of initial excel file isn
    t saving correctly and can
    t access cell by name using Range[] (getting invalid range exception).  But when I
    m saving file from the same stream and later opening saved file by full path, all work correctly.

    Please, help investigate an issue.


  • Posted 22 March 2022, 7:10 pm EST


    Can you please share your excel file with the stripped-down code which is having the issue at your end?

    It will help us to see if there is wrong with the code or there is some issue in the API.


    Prabhat Sharma.

  • Posted 22 March 2022, 9:46 pm EST

    var cloudBlob = _blobConteiner.GetBlockBlobReference(fullFilePath);
    MemoryStream templateContent = new MemoryStream();
    cloudBlob.DownloadToStream(templateContent );
    var workbook = new GrapeCity.Documents.Excel.Workbook(libraryLicenseKey);
    workbook.Open(templateContent); // loading data from MemoryStream

    Method DownloadToStream download file data from blob storage to Memory Stream.

    When creating workbook from MemoryStream getting file without formatting and template data

    Stream templateContent = File.Open(filePath, FileMode.Open);
    var workbook = new GrapeCity.Documents.Excel.Workbook(libraryLicenseKey);

    And when creating from FileStream (File.Open(filePath) returns FileStream) file is populated with data with saved headers.

    Borders between cells are disappeared in both cases.

  • Posted 23 March 2022, 9:58 pm EST


    It might be possible that the MemoryStream content that you are getting from the DownloadToStream method, might be corrupted.

    Can you please share the content of your MemoryStream via Text file replicating the issue? As it is not possible for us to replicate the issue with your given code at our end.


    Prabhat Sharma.

  • Posted 27 March 2022, 9:38 pm EST

    In this archive you can find the content of MemoryStream in the text file and excel, that was read using MemoryStream

  • Posted 28 March 2022, 7:56 pm EST - Updated 29 September 2022, 6:32 am EST


    First of all thank you for sharing your MemoryStream content.

    Please find the output of the excel file that is created using your MemoryStream content.

    If it is different from the expected output then please share your exported file so that we can see the difference.

    The code we are using is:

    MemoryStream stream = new MemoryStream(File.ReadAllBytes("test.txt"));
    var workbook1 = new GrapeCity.Documents.Excel.Workbook();


    Prabhat Sharma.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels