How to show a Xlsio IWorkbook in a Spreadsheet control

I have created an IWorkbook using Xlsio, and I also have a Spreadsheet control. How can I show the IWorkbook in the Spreadsheet control? 

5 Replies 1 reply marked as answer

AD Arunkumar Devendiran Syncfusion Team June 17, 2020 01:56 PM UTC

Hi Arvind,  
 
Thank you for your patience. 
 
We have checked your reported requirement “To open the workbook in spreadsheet” and it can be achievable in our EJ2 Spreadsheet as like in the below code example. 
 
Code Example: 
 
public IActionResult Open(IFormCollection openRequest) 
        { 
            ExcelEngine excelEngine = new ExcelEngine(); 
            IApplication application = excelEngine.Excel; 
            OpenRequest open = new OpenRequest(); 
            string filePath1 = Startup._env.ContentRootPath.ToString() + "/Files/File1.xlsx"; 
            FileStream inputStream1 = new FileStream(filePath1, FileMode.Open); // opened the existing file  
            IWorkbook workbook = application.Workbooks.Open(inputStream1);  // created the workbook 
            FileStream fileStream = new FileStream(Startup._env.ContentRootPath.ToString() + "/Files/ModifiedFile.xlsx", FileMode.Create); 
            workbook.SaveAs(fileStream); // save the workbook to stream 
            inputStream1.Close(); 
            IFormFile formFile = new FormFile(fileStream, 0, fileStream.Length, "", "ModifiedFile.xlsx"); // converting MemoryStream to IFormFile  
            open.File = formFile; 
            var content = Workbook.Open(open); 
            fileStream.Dispose(); 
            return Content(content); 
 
        } 
 
For your convenience, we have prepared the sample based on your requirement by overriding the Open method. Please find the link below. 
 
 
Could you please check the above sample and get back to us, if you need any further assistance on this. 
 
Regards, 
Arunkumar D 


Marked as answer

AR Arvind June 17, 2020 06:42 PM UTC

Thanks that works!

Is there a way to load the Spreadsheet control with the IWorkbook when the Spreadsheet control is first created? So when the Spreadsheet control is created, the IWorkbook loads the 'File1.xlsx' file and then the IWorkbook is set in the Spreadsheet control, instead of during Open. 




AD Arunkumar Devendiran Syncfusion Team June 18, 2020 11:13 AM UTC

Hi Arvind,  
 
Thank you for your update. 
 
We have checked your reported requirement “To open the workbook in spreadsheet at initial load” and it can be achievable in our EJ2 Spreadsheet as like in the below code example in created event and openFromJson method. 
 
Code Example: 
 
 
<ejs-spreadsheet id="spreadsheet" openUrl="Home/Open" saveUrl="Save" created="onCreated"> 
</ejs-spreadsheet> 
function onCreated() { 
        var ssObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet'); 
 
        $.ajax({ 
            type: "POST", 
            url: "Home/OpenFile", 
            contentType: "application/json; charset=utf-8", 
            dataType: 'json', 
            success: function (data) { 
                ssObj.openFromJson({ file: data }); 
            } 
        }) 
    } 
 
For your convenience, we have prepared the sample based on your requirement by overriding the Open method. Please find the link below. 
 
Sample Link:  
 
Could you please check the above sample and get back to us, if you need any further assistance on this. 
 
Regards, 
Arunkumar D 



AR Arvind June 20, 2020 01:43 PM UTC

That works! Thanks Arunkumar.

Regards


AD Arunkumar Devendiran Syncfusion Team June 22, 2020 08:42 AM UTC

Hi Arvind 
  
Thanks for your update. 
  
We are happy to hear that your issue has been resolved. Please feel free to contact us if you need any further assistance on this.  
   
Regards,  
Arunkumar D  


Loader.
Up arrow icon