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)
{
try
{
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";
workbook.SaveAs(fileName);
workbook.Close();
excelEngine.Dispose();
System.Diagnostics.Process.Start(Path.GetFullPath(fileName));
}
catch
(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
this.Close();
}
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.
Thanks,
Johnson