Not able to load Excel file from serve to Spreadsheet

Hello,

I am unable to fetch a file from the server and load it into a spreadsheet using the open function.

My API returns a blob and I have followed the steps listed at https://www.syncfusion.com/forums/152140/open-remote-excel-file - used my own API to fetch the FileStream instead of a direct fetch call.

It seems like the open function is making another "fetch" which is failing (as observed in the network log).

Please help.

Thanks and regards,
Monisha

3 Replies

MV Madhan Venkateshan Syncfusion Team August 10, 2020 08:56 AM UTC

Hi Fnu Monisha, 
 
Good day to you 
 
We have prepared a sample to directly read stream using XlsIO and use the ‘openFromJson’ method in client side to open the excel file from stream with single fetch. Please refer the below code snippets and sample link. 
 
openFromServer(){ 
       fetch("http://localhost:55367/Home/OpenFromServer").then((response) => { 
            response.json().then((data) => { 
                this.spreadsheetObj.openFromJson({ file: data }); 
            }); 
        }); 
    } 
 
public string OpenFromServer() 
        { 
            ExcelEngine excelEngine = new ExcelEngine(); 
            IWorkbook workbook; 
            FileStream fs = System.IO.File.Open("./wwwroot/Sample1.xlsx", FileMode.Open); // converting excel file to stream 
            workbook = excelEngine.Excel.Workbooks.Open(fs, ExcelOpenType.Automatic); // coverting stream to XlsIO workbook 
            MemoryStream outputStream = new MemoryStream(); 
            workbook.SaveAs(outputStream); 
            IFormFile formFile = new FormFile(outputStream, 0, outputStream.Length, "", "Sample1.xlsx"); // converting MemoryStream to IFormFile 
            OpenRequest open = new OpenRequest(); 
            open.File = formFile; 
            fs.Close(); 
            return Workbook.Open(open); // Return Spreadsheet readable data 
        } 
 
 
 
Regards, 
Madhan V 



FM Fnu Monisha August 10, 2020 10:05 PM UTC

Hello,

Thank you for your response.

The provided code is not working for .xlsm files. We need to load macro-enabled worksheets and save them as .xlsm files as well.
Please confirm if this feature is available.

Regards,
Monisha



MV Madhan Venkateshan Syncfusion Team August 11, 2020 01:02 PM UTC

Hi Fnu Monisha, 
 
Good day to you. 
 
We would let you know that we do not have support to load macro enabled worksheet. 
 
Regards, 
Madhan V 


Loader.
Up arrow icon