Changing the active sheet in ASP.NET Core Spreadsheet control

24 Jul 20261 minute to read

You can change the active sheet of the imported file by updating the activeSheetIndex property in the openComplete event.

To change the active sheet after importing an Excel file:

  1. Bind the openComplete event to the Spreadsheet.
  2. In the event handler, set the activeSheetIndex property to the index of the sheet you want to activate.
  3. Open an Excel file in the Spreadsheet.
  4. After the file is loaded, the Spreadsheet displays the sheet specified by the activeSheetIndex property.

The following code example demonstrates how to change the active sheet after importing an Excel file.

<ejs-spreadsheet id="spreadsheet" openUrl="Open" openComplete="openComplete">

</ejs-spreadsheet>

<script>

    function openComplete(args) {
        var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet');
        if (spreadsheetObj) {
            spreadsheetObj.activeSheetIndex = 2;
        }
    }

</script>
public IActionResult Open(IFormCollection openRequest)
{
    OpenRequest open = new OpenRequest();
    open.File = openRequest.Files[0];
    return Content(Workbook.Open(open));
}