2016-05-30 5 views

Antwort

1

gefunden die Antwort dafür. Binding Konzept früher verwendet wurde, kann nun auch in dem Beispiel, wie gezeigt https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/bindingcollection.md

(function() { 
// Create myTable 
Excel.run(function (ctx) { 
    var table = ctx.workbook.tables.add("Sheet1!A1:C4", true); 
    table.name = "myTable"; 
    return ctx.sync().then(function() { 
     console.log("MyTable is Created!"); 

     //Create a new table binding for myTable 
     Office.context.document.bindings.addFromNamedItemAsync("myTable", Office.CoercionType.Table, { id: "myBinding" }, function (asyncResult) { 
      if (asyncResult.status == "failed") { 
       console.log("Action failed with error: " + asyncResult.error.message); 
      } 
      else { 
       // If successful, add the event handler to the table binding. 
       Office.select("bindings#myBinding").addHandlerAsync(Office.EventType.BindingDataChanged, onBindingDataChanged); 
      } 
     }); 
    }) 
    .catch(function (error) { 
     console.log(JSON.stringify(error)); 
    }); 
}); 

// When data in the table is changed, this event is triggered. 
function onBindingDataChanged(eventArgs) { 
    Excel.run(function (ctx) { 
     // Highlight the table in orange to indicate data changed. 
     var fill = ctx.workbook.tables.getItem("myTable").getDataBodyRange().format.fill; 
     fill.load("color"); 
     return ctx.sync().then(function() { 
      if (fill.color != "Orange") { 
       ctx.workbook.bindings.getItem(eventArgs.binding.id).getTable().getDataBodyRange().format.fill.color = "Orange"; 

       console.log("The value in this table got changed!"); 
      } 
      else 

     }) 
      .then(ctx.sync) 
     .catch(function (error) { 
      console.log(JSON.stringify(error)); 
     }); 
    }); 
} 

})() verwendet werden;

Verwandte Themen