locked
Client side (office javascript api) vs server side (asp.net) RRS feed

  • Question

  • User-854857924 posted

    On the basis of this article , I created a ms sql database, including the models and controllers in a Excel Web AddIn (TaskPane)

    How can I populate the contents of the table Movie in Excel?

    This is the controller:

    namespace DatabaseWeb.Controllers
    {
        public class controllerMovie : Controller
        {
            private modelMovie db = new modelMovie();
    
            // GET: controllerMovie
            public ActionResult Index()
            {
                return View(db.Movies.ToList());
            }

    This is the javascript (not working)

    function loadSampleData() {
    
            var db = new Controllers.controllerMovie();
    
            var values = db.ActionResult;
    
            // Run a batch operation against the Excel object model
            Excel.run(function (ctx) {
                // Create a proxy object for the active sheet
                var sheet = ctx.workbook.worksheets.getActiveWorksheet();
                // Queue a command to write the sample data to the worksheet
                sheet.getRange("B3:D5").values = values;
    
                // Run the queued-up commands, and return a promise to indicate task completion
                return ctx.sync();
            })
            .catch(errorHandler);
        }

     

    Monday, August 15, 2016 7:05 AM

All replies

  • User-854857924 posted

    I tried the following with no luck

    function loadSampleData() {
    
            var values = getMovies();
    
            // Run a batch operation against the Excel object model
            Excel.run(function (ctx) {
    
    
                // Create a proxy object for the active sheet
                var sheet = ctx.workbook.worksheets.getActiveWorksheet();
                // Queue a command to write the sample data to the worksheet
                sheet.getRange("B3:D5").values = values;
    
                // Run the queued-up commands, and return a promise to indicate task completion
                return ctx.sync();
            })
            .catch(errorHandler);
        }

        function getMovies() {
           
            $.ajax({
                type: "GET",
                url: "Controllers/controllerMovie",
                success: function (result) {
                    return result;
                },
                error: function (response) {
                    return "fout";
                }
            });
    
        }

    Monday, August 15, 2016 10:38 AM