How to return Excel data in ASP.NET Web API response without storing to disk

Posted by: jayram.tallamraju on 2 April 2018, 1:37 pm EST

  • Posted 2 April 2018, 1:37 pm EST

    Hi,
    I was able to load Excel file to do required data manipulation using Spread.Services.
    However I am not finding a way to return modified Workbook as stream directly to ASP.NET API Response.
    Don't want to save changes to disk and return saved file.
    Is there a way to directly to write to Memory stream or something and return in API Response [And avoid Disk Save and Read of changes]
    Please provide any quick code snippet if possible.
    Thanks
  • Marked as Answer

    Replied 3 April 2018, 5:45 pm EST

    Hi Jayram,

    You can use the toJSON method of workbook object to generate a zip json string using stream.
    For example:

     Workbook workbook = new Workbook();
    IWorksheet worksheet = workbook.Worksheets[0];
    worksheet.Range["A1:A3"].Value = 121;
    FileStream stream = new FileStream("file.txt", FileMode.Create, FileAccess.Write);
    workbook.ToJson(stream);


    http://help.grapecity.com/spread/SpreadServices/webframe.html#GrapeCity.Documents.Spread~GrapeCity.Documents.Spread.IWorkbook~ToJson(Stream).html

    I hope it helps.

    Thanks,
    Deepak Sharma
Need extra support?

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

Learn More

Forum Channels