Skip to main content
A newer version of this page is available. .

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

Declaration

public static event InitializeDocumentEventHandler InitializeDocument

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.

Remarks

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

Example

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) {
        if(!Page.IsPostBack)
            ReopenDocument();
    }

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

    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