0

I am attempting to open a password protected excel file (versions xls, xlsx, xlsm). I need to open the files and remove the password from each file. I have all the passwords available for the files that are to be processed.

I cant use Microsoft Interop Excel as excel must be installed on the server for this to work. I am already using Aspose.Cells to open non password protected files. But i want to be able to save the file overwrite it without its password.

Has anybody any suggestions? Thanks in advance

Code so far

public static void RemovePassword(string filePath, string password){
  LoadOptions loadOptions = new LoadOptions();
  loadOptions.Password = password;

  Workbook src = new Workbook(filePath, loadOptions);
  //need a way of removing the password from the file.
}

2 Answers 2

2

You can use the Unprotect method of Workbook:

LoadOptions loadOptions = new LoadOptions();
loadOptions.Password = password;

Workbook workbook = new Workbook(filePath, loadOptions);
workbook.Unprotect(password);
// or workbook.Settings.Password = "";
workbook.Save(filePath);
Sign up to request clarification or add additional context in comments.

1 Comment

is this applied to the encrypted file to be (pass) removed?
0

Thanks for your answer, I have noticed that your first suggestion only unprotects the workbooks structure.

workbook.Unprotect(password);

In my case i want to unencrypt an actual file that is password protected(encrypted)

The second suggestion works great thanks!

 workbook.Settings.Password = "";
 workbook.Save(filePath);

Thanks Again for your help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.