Search code examples
excelencryptionopenxmlopenxml-sdkpassword-encryption

Is it possible to create an encrypted Excel file with the OpenXML SDK


I'm working on a C# project that create, encrypt and send an excel file as an e-mail attachment. I'm not looking to protect the excel, but encrypt it and set a password for opening it. Is it even possible with the OpenXML SDK ? I tried that, but I don't think this is for encrypting :

string hexConvertedPassword = HexPasswordConversion("Azerty123");
WorkbookProtection WorkbookProt = new WorkbookProtection()
{
    WorkbookPassword = hexConvertedPassword,
    RevisionsPassword = hexConvertedPassword,
    LockRevision = true,
    LockStructure = true,
    LockWindows = true,
};
Workbook workbook = new Workbook();
workbook.Append(WorkbookProt);

I have already search in the documentation, but may have missed it.

I know some library can do it like devexpress, EasyXLS, Spire.Xls, etc, but those are very expensive.


Solution

  • In the end I used FreeSpire.XLS to load my existing Excel file and add the encryption over it. Hopefully there is no limitation to load and save file with the free version.