A newer version of this page is available. Switch to the current version.

ASPxSpreadsheet.InitializeDocument Event

Occurs before a document is loaded. Handle this event to set initial document settings.

Namespace: DevExpress.Web.ASPxSpreadsheet

Assembly: DevExpress.Web.ASPxSpreadsheet.v18.2.dll


public static event InitializeDocumentEventHandler InitializeDocument
Public Shared Event InitializeDocument As InitializeDocumentEventHandler

Event Data

The InitializeDocument event's data class is SpreadsheetInitializeDocumentEventArgs. The following properties provide information specific to this event:

Property Description
Document Provides access to a workbook loaded into a Spreadsheet.


The InitializeDocument event enables you to make the necessary adjustments in the document model while the document is being opened for the first time.


The sample demonstrates how to handle the Spreadsheet's ASPxSpreadsheet.InitializeDocument event to password protect the loaded document by specifying its password in code.

using DevExpress.Spreadsheet;
using DevExpress.Web.ASPxSpreadsheet;
using DevExpress.Web.Office;

    protected void Page_Load(object sender, EventArgs e) {

    protected void ReopenDocument() {
        ASPxSpreadsheet.InitializeDocument += ASPxSpreadsheet_InitializeDocument;
        string filePath = Server.MapPath("~/App_Data/WorkDirectory/AutoFilter.xlsx");

    protected static void ASPxSpreadsheet_InitializeDocument(object sender, SpreadsheetInitializeDocumentEventArgs e) {
        e.Document.EncryptedFilePasswordRequest += Document_EncryptedFilePasswordRequest;

    private static void Document_EncryptedFilePasswordRequest(object sender, EncryptedFilePasswordRequestEventArgs e) {
        if(e.DocumentName.EndsWith("AutoFilter.xlsx")) {
            e.Password = "123";
            e.Handled = true;
See Also