none
Excel - control read and write area RRS feed

  • Question

  • Hi all,

    My scenario is this: I need to read a bunch of data from a web service. Display it as an excel sheet, and once the user is done editing, publish changes back to the web service.

    I would very much like to use App for office. So far, my problems are:

    • How to set the data to the whole page after It has been read (I and only start setting in the selected spot)?
    • How to track changes?
    • How to persist the users login details provided at the task pane so that he doesn't have to reenter them each time he uses the pane?

    Thanks,

    Asher

    Thursday, February 27, 2014 5:59 AM

Answers

  • Hi Asher,

    >> How to set the data to the whole page after It has been read (I and only start setting in the selected spot)? <<

    I assume you will retrieve JSON array in client side, you could use Document.setSelectedDataAsync method to set data.

    >> How to track changes <<

    Data Binding callback will be triggered when data being changed, but it would not tell which cell had been changed. So I’m afraid we are not able to track cell data change currently. To save changes, you may need to submit all data to server and compare which cells are changed.

    >> How to persist the users login details provided at the task pane so that he doesn't have to reenter them each time he uses the pane? <<

    What do you mean by “login details”? For user name and password, you could save them to cookie like a normal Web Application (refer to Authenticated Web Slices).

    For customization settings, you could use Settings Object to persist app state and settings.

    Sample for your reference:

    /// <reference path="../App.js" />
    
    (function () {
        "use strict";
        var bindingName = "myTableBidning";
    
        var onBindingDataChanged = function (result) {
            // refresh data
        }
    
        // The initialize function must be run each time a new page is loaded
        Office.initialize = function (reason) {
            $(document).ready(function () {
                app.initialize();
                $('#create-new-table').click(createNewTable);
            });
        };
    
    
        function createNewTable() {
            // Build table.
            var myTable = new Office.TableData();
    
            myTable.headers = [["ID", "Name"]];
            myTable.rows = [["1", "Hello"], ["2", "World"], ["3", "Apps for Office"]];
    
            // Write table.
            Office.context.document.setSelectedDataAsync(myTable, { coercionType: Office.CoercionType.Table },
                function (result) {
                    var error = result.error
                    if (result.status === "failed") {
                        app.showNotification(error.name + ":", error.message);
                    }
    
                    Office.context.document.bindings.addFromSelectionAsync(
                        Office.BindingType.Table,
                        { id: bindingName },
                        function (result) {
                            var error = result.error
                            if (result.status === "failed") {
                                app.showNotification(error.name + ":", error.message);
                            } else {
                                addBindingsHandler();
                            }
                        }
                    );
                });
        }
    
        function addBindingsHandler(callback) {
            Office.select("bindings#" + bindingName).addHandlerAsync(
              Office.EventType.BindingDataChanged,
              onBindingDataChanged,
              function () {
                  if (callback) { callback(); }
              });
        }
    })()

    If you have any feedbacks for Office Development Platform, please feel free to submit them to User Voice.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Asher_barak Monday, March 3, 2014 8:35 AM
    Friday, February 28, 2014 6:45 AM
    Moderator