0
votes

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

2 Answers

2
votes

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);
0
votes

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