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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to check an excel file requires password.

Thread ID:





105015 Sep 3,2012 08:36 AM UTC Sep 6,2012 11:31 AM UTC Silverlight 3
Tags: XlsIO
Jaeyeol Shin
Asked On September 3, 2012 08:36 AM UTC

Hi. My code to read an excel file is below. 

excelEngine.Excel.Workbooks.Open(stream, ExcelOpenType.Automatic);

This code will occur ArgumentException when reading an encrypted excel file.
How can I check an excel file is encrypted or not?

Johnson Monohar M [Syncfusion]
Replied On September 5, 2012 06:13 AM UTC

Hi Jaeyeol Shin,

Thank you for using Syncfusion products.

XlsIO doesn’t have any property or a method to check whether the file is encrypted or not. However, this can be achieved by an event “OnPasswordRequired” provided at its application level. This event will be raised if an encrypted file is tried to open without its password, where you can provide the password and proceed or else you can stop parsing the workbook.

The following code snippets helps you to achieve this.

private void btnCreateExcel_Click(object sender, System.EventArgs e)




                ExcelEngine excelEngine = new ExcelEngine();


                IApplication application = excelEngine.Excel;

                application.OnPasswordRequired += application_OnPasswordRequired;

                application.DefaultVersion = ExcelVersion.Excel2010;


                IWorkbook workbook = application.Workbooks.Open(@"../../Data/Sample.xlsx", ExcelOpenType.Automatic);

                IWorksheet sheet = workbook.Worksheets[0];


                workbook.Version = ExcelVersion.Excel2010;

                string fileName = @"../../Output/Output.xlsx";









            catch (Exception ex)







void application_OnPasswordRequired(object sender, PasswordRequiredEventArgs e)


e.NewPassword = "syncfusion";


In addition, we have provided you a sample with the above code snippets for your reference in the following link.

Sample Link : EncryptedExcel.zip

Kindly refer to the provided solution and let us know whether the provided solution has resolved your issue or if you need any clarification.


Jaeyeol Shin
Replied On September 5, 2012 08:19 AM UTC

Thank you Johnson.

Is there any idea to distinguish an ArgumentException caused by missing password?

Johnson Monohar M [Syncfusion]
Replied On September 6, 2012 11:31 AM UTC

Hi Jaeyeol Shin,

It is not possible to distinguish ArgumentException for missing password. Only by the provided event in the previous post, we can be able to identify for missing password.

Please let me know if you have any other queries.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon