Encrypt with Password

This demo uses the DevExpress Spreadsheet Document API to encrypt documents. You can process the sample file or supply your own document. To do the latter, select Upload a File from the file selection drop-down menu.

You can specify the encryption type and password. Use the Encrypt and Save as... dropdown button to select the output format, encrypt the workbook, and download the result.

Sample document
InvestmentPortfolio.xlsx



using DevExpress.Spreadsheet;

Stream EncryptDocumentWithPassword(Stream inputStream, DocumentFormat outputFormat, string password, EncryptionType encryptionType) {
    using var workboook = new Workbook();

    workboook.LoadDocument(inputStream);

    var encryptionSettings = new EncryptionSettings {
        Password = password,
        Type = encryptionType
    };

    var outputStream = new MemoryStream();

    workboook.SaveDocument(outputStream, outputFormat, encryptionSettings);

    outputStream.Position = 0;
    return outputStream;
}