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.
using DevExpress.Spreadsheet;
Stream EncryptDocumentWithPassword(Stream inputStream, DocumentFormat outputFormat, string password, EncryptionType encryptionType) {
using var workboook = new Workbook();
// Load document from stream
workboook.LoadDocument(inputStream);
// Create encryption settings
var encryptionSettings = new EncryptionSettings {
Password = password,
Type = encryptionType
};
// Prepare output stream
var outputStream = new MemoryStream();
// Save the encrypted document
workboook.SaveDocument(outputStream, outputFormat, encryptionSettings);
outputStream.Position = 0;
return outputStream;
}