How to view xlsx file in the Spreadheet Control?

2 posts, 0 answers
  1. Artur
    Artur avatar
    4 posts
    Member since:
    Sep 2014

    Posted 15 Oct 2015 Link to this post

    Hello Telerik Team,

    Let's assume there is a xlsx file and I want to load this file to Spreadheet control.

     

    Controller code:

    var workbook = Workbook.Load(​path);  
    var workbookJson = workbook.ToJson();
                                            
    var model = new ExcelViewerViewModel()
    {
    Name = "Test",
    Sheets = JsonConvert.DeserializeObject<IEnumerable<SpreadsheetSheet>>(workbookJson),   <--- the problem to deserialize sheets
    };

    return PartialView("~/Views/Shared/_ExcelViewer.cshtml", model);

     

    The View code:

                @(Html.Kendo().Spreadsheet()
                    .Name("excelViewer")                                
                    .Toolbar(false)                       
                    .BindTo(Model.Sheets))

     

    So the question is how to get IEnumerable<SpreadsheetSheet>> type from workbook?

     

     Thank You

     

  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 19 Oct 2015 Link to this post

    Hi,

    I'm copying the reply to your support ticket for community reference:

    This is a good question. Ideally, the Spreadsheet helper will take a Workbook reference directly.
    But this would require introducing a dependency to Telerik.Web.Spreadsheet and all assemblies required by it (which are a whole lot).

    We're still pondering on how to solve this. Perhaps a third assembly, say Telerik.Web.Spreadsheet.Model, containing only the model interface definitions will solve this.
    There might be some breaking changes regarding this, but we haven't made a decision yet.

    For the moment, my recommendation is to load the JSON data directly on the client:
      var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
      $.getJSON("/kendo-ui/content/web/spreadsheet/products.json")
      .done(function (sheets) {
         spreadsheet.fromJSON({ sheets: sheets });
      }); 

    I hope this helps.

    Regards,
    T. Tsonev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top