We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Problem opening .xlsm Excel macro file using XlsIO UWP

Hello

Thanks for a great product.

Im having trouble opening a excel file with macro in a UWP app.

My code looks like this:

using (ExcelEngine excelEngine = new ExcelEngine())
            {
                excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016;
                IApplication application = excelEngine.Excel;

                try
                {
                    var uri = new Uri("ms-appx:///Docs/Cert.xlsm");
                    var cert = await StorageFile.GetFileFromApplicationUriAsync(uri);
                    application.SkipOnSave = SkipExtRecords.None;
                    application.SkipOnSave = SkipExtRecords.CopySubstreams;
                    Stream stream = await cert.OpenStreamForReadAsync();
                    IWorkbook workbook = await excelEngine.Excel.Workbooks.OpenAsync(stream, ExcelOpenType.Automatic);
                    IWorksheet worksheet = workbook.Worksheets[0];
                    worksheet.Range["B2"].Text = OrderNr;
                    //worksheet.Range["E6"].Text = Kunde;
                    worksheet.Range["B5"].Text = Skib;
                    #region Save the Workbook
                    StorageFile storageFile;
                    storageFile = await suscces.CreateFileAsync(OrderNr + " MV" + Skib + " Certificates.xlsm", CreationCollisionOption.ReplaceExisting);
                    if (storageFile != null)
                    {
                        //Saving the workbook
                        await workbook.SaveAsAsync(storageFile);
                        workbook.Close();
                    }
                    #endregion
                }
                catch (Exception)
                {

                }


            }

It fails on IWorkbook workbook = await excelEngine.Excel.Workbooks.OpenAsync(stream, ExcelOpenType.Automatic);

If I change the file to an xlsx excel file without macros it works no problem. 

I cant find anywhere that xlsm should not be included in the UWP version.

Thanks.


3 Replies

SS Sridhar Sukumar Syncfusion Team December 15, 2016 12:29 PM UTC

Hi Kasper, 

 

Thank you for contacting Syncfusion support. 

 

We are unable to reproduce the issue from our side. We have shared a simple sample for your reference.  which can be downloaded from following location. 

 

Sample link:  

http://www.syncfusion.com/downloads/support/directtrac/general/ze/App3723382377.zip 

 

Kindly modify the sample to reproduce the issue and share us the modified sample along with the issue reproducing input files which will be helpful for us to give you a prompt solution at the earliest. 

 

Please let us know if you have any concerns. 

 

Regards, 

Sridhar S. 


KM Kasper Mathiesen December 20, 2016 10:03 AM UTC

Hello Sridhar

Thank you for your reply I have downloaded the sample file and can confirm that it works as it should with the Sample.xlsm.

How ever if i try inputting my xlsm fil it gives the following exceptions:

Exception thrown: 'System.Exception' in mscorlib.ni.dll
Exception thrown: 'System.Exception' in mscorlib.ni.dll
Exception thrown: 'System.AggregateException' in mscorlib.ni.dll

It is a big Excel file with multiple tabs and macros, so that might be the cause.


SS Sridhar Sukumar Syncfusion Team December 21, 2016 12:04 PM UTC

Hi Kasper, 
 
Thank you for updating us. 
 
We also suspect that the issue might be raised from your input file. So, we kindly request you to share the Excel document along with complete stack trace of the exception which will be helpful for us to give you a prompt solution at earliest. 
 
Note: We use the shared document only for validation purpose. We will delete the document after completing the validation. 
 
Regards, 
Sridhar S. 


SIGN IN To post a reply.
Loader.
Up arrow icon