IXlExporter.CreateDocument(Stream, EncryptionOptions) Method
Creates a password-protected document using the specified encryption options.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.1.Core.dll
NuGet Package: DevExpress.Printing.Core
Declaration
Parameters
Name | Type | Description |
---|---|---|
stream | Stream | The System.IO.Stream object to output the document to. |
encryptionOptions | EncryptionOptions | An EncryptionOptions object containing encryption settings. |
Returns
Type | Description |
---|---|
IXlDocument | An IXlDocument object that is the newly created encrypted workbook. |
Remarks
Note
When you finish working with the IXlDocument
object, call the Dispose method to release all the resources used by the object. Otherwise, generated content is not written to the output file. You can also modify the IXlDocument
object within the using statement (Using block in Visual Basic).
Example
Note
A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples
// Create an exporter instance.
IXlExporter exporter = XlExport.CreateExporter(documentFormat);
// Specify encryption options.
// A workbook will be encrypted using the default encryption mechanism
// (agile encryption for XLSX files, and RC4 encryption for XLS files).
EncryptionOptions encryptionOptions = new EncryptionOptions();
// Specify the encryption password.
encryptionOptions.Password = "password";
// Create a new document and encrypt its contents.
using (IXlDocument document = exporter.CreateDocument(stream, encryptionOptions))
{
// Specify the document culture.
document.Options.Culture = CultureInfo.CurrentCulture;
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CreateDocument(Stream, EncryptionOptions) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.