Skip to main content

How to: Access the Spreadsheet Editor Controls

  • 3 minutes to read

This topic describes how to access and customize the following controls in XAF applications with the Office Module:

Platform

Control

Purpose

WinForms

SpreadsheetControl

Used to show Spreadsheet documents

ASP.NET Web Forms

ASPxSpreadsheet

Used to show Spreadsheet documents

ASP.NET Web Forms

ASPxUploadControl

Used to upload Spreadsheet documents to a server

Note

XAF does not support the Spreadsheet editor for ASP.NET Core Blazor applications.

Access the WinForms-Specific Control (SpreadsheetControl)

Follow the steps below to access the SpreadsheetControl and restrict the number of visible rows and columns in a worksheet.

  1. Create a custom ViewController in the WinForms application project (MySolution.Win).
  2. In the overridden OnActivated method, get the SpreadsheetServiceController and subscribe to its CustomizeSpreadsheetControl event.
  3. In the CustomizeSpreadsheetControl‘s handler, access the SpreadsheetControl and subscribe to its DocumentLoaded event.
  4. In the DocumentLoaded event handler, use the SetSize method to specify the number of visible rows and columns for an active worksheet.

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Office.Win;
    using DevExpress.Spreadsheet;
    using DevExpress.XtraSpreadsheet;
    // ...
    public class WinSpreadsheetController : ViewController {
        protected override void OnActivated() {
            base.OnActivated();
            SpreadsheetServiceController controller = Frame.GetController<SpreadsheetServiceController>();
            if(controller != null) {
                controller.CustomizeSpreadsheetControl += Controller_CustomizeSpreadsheetControl;
            }
        }
        private void Controller_CustomizeSpreadsheetControl(object sender, CustomizeSpreadsheetEventArgs e) {
            SpreadsheetControl spreadsheetControl = ((SpreadsheetPropertyEditor)sender).SpreadsheetControl;
            spreadsheetControl.DocumentLoaded += SpreadsheetControl_DocumentLoaded;
        }
        private void SpreadsheetControl_DocumentLoaded(object sender, System.EventArgs e) {
            SpreadsheetControl spreadsheetControl = (SpreadsheetControl)sender;
            Worksheet worksheet = spreadsheetControl.ActiveWorksheet;
            spreadsheetControl.WorksheetDisplayArea.SetSize(worksheet.Index, 5, 10);
        }
    }
    

Access ASP.NET Web Forms-Specific Controls

Access the ASPxSpreadsheet Control

Follow the steps below to access the ASPxSpreadsheet control and restrict the number of visible rows and columns in a worksheet.

  1. Create a custom ViewController in the ASP.NET Web Forms module project.
  2. In the overridden OnActivated method, handle the ASPxSpreadsheetPropertyEditor.ControlCreated event.
  3. In the event handler, use the SetSize method to specify the number of visible rows and columns.

    using System;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Office.Web;
    using DevExpress.Web.ASPxSpreadsheet;
    // ...
    public class WebSpreadsheetController : ViewController<DetailView> {
        protected override void OnActivated() {
            base.OnActivated();
            foreach (ASPxSpreadsheetPropertyEditor editor in View.GetItems<ASPxSpreadsheetPropertyEditor>()) {
                if (editor.ASPxSpreadsheetControl != null) {
                    editor.ASPxSpreadsheetControl.Load += SpreadsheetControl_Load;;
                }
                else {
                    editor.ControlCreated += Editor_ControlCreated;
                }
            }
        }
        void Editor_ControlCreated(object sender, EventArgs e) {
            ASPxSpreadsheet spreadsheet = ((ASPxSpreadsheetPropertyEditor)sender).ASPxSpreadsheetControl;
            spreadsheet.Load += SpreadsheetControl_Load;
        }
        void SpreadsheetControl_Load(object sender, EventArgs e) {
            ASPxSpreadsheet spreadsheetControl = (ASPxSpreadsheet)sender;
            spreadsheetControl.WorksheetDisplayArea.SetSize(0, 5, 10);
        }
    }
    

Access the ASPxUploadControl

Follow the steps below to access the ASPxUploadControl and set the maximum size of the file to be uploaded on a server.

  1. Create a custom ViewController in the ASP.NET Web Forms module project.
  2. In the overridden OnActivated method, handle the ASPxSpreadsheetPropertyEditor.ControlCreated event.
  3. In the event handler, use the MaxFileSize method to specify the maximum size of the file to be uploaded on a server.
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Office.Web;
using DevExpress.Web;
using System;
// ...
public class WebSpreadsheetUploadController : ViewController<DetailView> {
    protected override void OnActivated() {
        base.OnActivated();
        foreach (ASPxSpreadsheetPropertyEditor editor in View.GetItems<ASPxSpreadsheetPropertyEditor>()) {
            if (editor.ASPxUploadControl != null) {
                CustomizeSpreadsheetUploadControl(editor.ASPxUploadControl);
            }
            else {
                editor.ControlCreated += Editor_ControlCreated;
            }
        }
    }
    private void Editor_ControlCreated(object sender, EventArgs e) {
        ASPxUploadControl spreadsheetUploadControl = ((ASPxSpreadsheetPropertyEditor)sender).ASPxUploadControl;
        CustomizeSpreadsheetUploadControl(spreadsheetUploadControl);
    }
    private void CustomizeSpreadsheetUploadControl(ASPxUploadControl uploadControl) {
        uploadControl.ValidationSettings.MaxFileSize = 104857600;
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        foreach (ASPxSpreadsheetPropertyEditor editor in View.GetItems<ASPxSpreadsheetPropertyEditor>()) {
            editor.ControlCreated -= Editor_ControlCreated;
        }
    }
}
See Also