Ticket T183259
Visible to All Users

Spreadsheet - How to access an active sheet in the Controller

created 10 years ago (modified 10 years ago)

Hi

I would like to access the active sheet of the current document (ASP.NET - MVC - cshtml) in the View. I have been trying to use the following code:

JavaScript
function ChangeCellValue(s, e) {          $.ajax({             url: '@Url.Action("Test", "Home")',             //How do I get access to the activeSheet here ?            data: { activeCellColumnIndex: s.GetSelection().activeCellColumnIndex, activeCellRowIndex: s.GetSelection().activeCellRowIndex },             contentType : 'application/html; charset=utf-8' ,             dataType: "text",             traditional: true,             success: function (result) {                   alert(result);             },         });     }
C#
@Html.DevExpress().Spreadsheet(     settings =>     {         settings.Name = "Spreadsheet";         settings.CallbackRouteValues = new { Controller = "SpreadsheetAPI", Action = "CellValuePartial" };         settings.Width = Unit.Percentage(100);         settings.Height = 475;         settings.ActiveTabIndex = 0;         settings.EnableClientSideAPI = true;         settings.PreRender = (s, e) =>         {             MVCxSpreadsheet spreadsheet = (MVCxSpreadsheet)s;             DXWebApplication2.Controllers.CellValueDemoHelper.PrepareWorksheet(spreadsheet.Document.Worksheets[0]);         };          settings.ClientSideEvents.SelectionChanged = "ChangeCellValue"     } ).GetHtml()   public ActionResult Test(int activeCellColumnIndex, int activeCellRowIndex  )         {             System.Diagnostics.Debug.WriteLine(SelRange);             string str = "activeCellColumnIndex = " + activeCellColumnIndex + "activeCellRowIndex = " + activeCellRowIndex ;             return Content(str);         }

Basically I am trying to get the current selection (client-side) of the active sheet as a Range data type. I want to access the selected range (multiple cells) similar to the following:

worksheet.Cells["B5"].

so that I can perform custom actions on the selected range.

For this, I require :

  1. Access to the client-side selected range as a Range datatype (of devexpress.spreadsheet) in the controller.
    OR
    2.Access to the active sheet in the controller.

Many thanks,
Sunaina

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hello,

On the server first obtain an active document using the SpreadsheetExtension.GetCurrentDocument method. This method will return you IWorkbook that can be modified according to your scenario. Please check the Spreadsheet Document help article learn more.
See also:
Cells and Cell Ranges

Thanks,
Artem

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.