Free Support Forum - aspose.com

Workbook unprotect not working

HI

I have an XLSX document that is protected with password

I open it using this:

   Dim lOpt As New Aspose.Cells.LoadOptions
   lOpt.Password = "xxxxxxxxxx"

   Using aWb As New Aspose.Cells.Workbook(filePath, lOpt)
   Dim sopt As New Aspose.Cells.OoxmlSaveOptions(Aspose.Cells.SaveFormat.Xlsx)
   
    aWb.Unprotect("xxxxxxxxxx")
    aWb.Save("c:\test.xlsx", sopt)
        
   End Using

Problem is that the output file c:\test.xlsx is still password protected…

How to I unprotect it and save without password.

Thanks in advance :slight_smile:

@farouche,

Thanks for your query.

Well, you need to specify the password (string) to null to remove the password or decrypt the file, see the updated line of code (in bold) for your reference:
e.g
Sample code:

Dim lOpt As New Aspose.Cells.LoadOptions
lOpt.Password = “xxxxxxxxxx”

Using aWb As New Aspose.Cells.Workbook(filePath, lOpt)
Dim sopt As New Aspose.Cells.OoxmlSaveOptions(Aspose.Cells.SaveFormat.Xlsx)

aWb.Settings.Password = Nothing
aWb.Save(“c:\test.xlsx”, sopt)

End Using

Hope, this helps a bit.

Hi

Thanks for the quick reply :slight_smile:

That did the trick and is somehow understandable …

But what is then the purpose of the Upprotect method ?

@farouche,

Well, Workbook.Unprotect() method is used to unprotect the protected workbook when using Review|Protect Workbook (menu) option in Ms Excel (or using Workbook.Protect() API), see the notes below. But your file is encrypted/password protected so you will use the suggested line of code to decrpyt it or remove its password protection.

Protect Workbook:
Protecting workbook helps you to keep others from making structural changes to your workbook, such as, moving, deleting or adding sheets, etc.

Hope, this helps a bit.

Hi again

Thanks for the answer.

That makes sense :slight_smile:

@farouche,

Good to know that you understand it now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.