C1FlexGrid: SaveGridExcel to stream: existing file

Posted by: wknauf on 26 October 2021, 12:38 am EST

    • Post Options:
    • Link

    Posted 26 October 2021, 12:38 am EST

    Hi C1,

    I am in the process of adding support to OneDrive/Office365 to our app: when saving a C1FlexGrid as excel file, the resulting file shall be written to OneDrive.

    So I don’t save the grid to a file but to a MemoryStream, and store the data of this stream to OneDrive.

    This causes trouble when saving multiple C1FlexGrid to a single file: “SaveGridExcel” to file has the feature to append sheets to an existing file if it does not contain the specified sheetname. We use this feature in one place.

    The stream method does not support this feature: each call to “SaveGridExcel” creates a new “C1XLBook”. So, no multi sheet document can be created.

    Would it be possible to add a “SaveGridExcel” overload that loads the C1XLBook from the specified stream and thus adds additional sheets?

    A workaround would be to save the grids to a temp file, and then upload this temp file to OneDrive.

    Best regards

    Wolfgang

  • Posted 26 October 2021, 4:18 pm EST

    Hi,

    We have forwarded your request to the development team and will let you know when we get an update.

    Regards

    Avnish

    [Internal Tracking ID: C1WIN-25984]

  • Posted 19 May 2022, 6:14 pm EST

    Hi,

    any updates on this?

    Best regards

    Wolfgang

  • Posted 25 May 2022, 4:38 pm EST

    Hi,

    We are getting in touch with the development team to get an update on this issue. We will let you know as soon as we have an update.

    Regards

    Avnish

  • Posted 11 April 2023, 6:35 pm EST

    Hi,

    any updates on this?

    Best regards

    Wolfgang

  • Posted 12 April 2023, 3:14 pm EST

    Hello Wolfgang,

    As of now, there is no update on this from the developers.

    We have asked again for updates on this issue and asked them if there are any plans to add this feature to the API.

    Regards,

    Prabhat Sharma.

  • Posted 7 December 2023, 8:09 am EST

    I found a changelog entry about this feature, so I gave it a test:

    [FlexGrid] Added saving multiple sheets using Stream to FlexGrid.ImportExport. (Jira:C1WIN-25984)

    See attached sample - click the button “Save to combined file” to combine the two grids in one xlsx file.

    FlexGridMultiSave.zip

    I hope my code is correct:

    MemoryStream streamToSave = new MemoryStream();
    this.c1FlexGrid1.SaveExcel(streamToSave, "Sheet 1", FileFlags.... | FileFlags.OpenXml);
    streamToSave.Seek(0, SeekOrigin.Begin);
    this.c1FlexGrid2.SaveExcel(streamToSave, "Sheet 2", FileFlags.... | FileFlags.OpenXml);
    streamToSave.Seek(0, SeekOrigin.Begin);
    File.WriteAllBytes("result.xlsx", streamToSave.ToArray());

    When opening the resulting file with excel, there is a warning about broken content, and excel asks whether it should restore the content. If you do so, the grid has two worksheets, and as far as I can see, all data is present. But the warning “broken file” is not good :wink:

    As you see, I am on .NET6 now. My initial question was about the 4.5.2 version.

    Best regards

    Wolfgang

  • Posted 7 December 2023, 7:12 pm EST

    Hi Wolfgang,

    Thanks a lot for sharing the sample project. We could also see the behavior on our end. We have shared all the observations with the development team to get their insights on it and will let you know the updates as soon as possible.

    Best Regards,

    Kartik

  • Posted 26 January 2024, 2:58 am EST

    I found this in the release notes and can confirm that this fixes my issue:

    [FlexGrid] When exporting to Excel using a stream and saving the stream to a file, the contents of the file were damaged. (Jira:C1WIN-31467)

    Best regards

    Wolfgang

Need extra support?

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

Learn More

Forum Channels