Home > Enterprise >  Put data from Worksheet into Taskpane
Put data from Worksheet into Taskpane

Time:03-01

I've got a taskpane and one of the fields I'd like to fill out from the worksheet.

How can I access data from Worksheets during Office Taskpane startup?

Example:

Office.onReady(function (info) {

    const range = context.workbook.getSelectedRange();

    // Read the range address
    range.load("address");

    // Update the fill color
    range.format.fill.color = "yellow";

})

gives error Context is undefined.

How can I load some data and send it up to the Taskpane on launch?

A simple example is, I have a Dropdown which I'd like to populate with column letters, but only from the usedrange.

CodePudding user response:

It looks like you are trying to use the Excel.RequestContext object. You need to get a reference to it before you call it. The recommended way to do this is to call Excel.run. It will automatically create the context object and pass it to the callback. Here's an example.

await Excel.run(async (context) => {
  var selectedRange = context.workbook.getSelectedRange();
  selectedRange.load('address');
  await context.sync();
  console.log('The selected range is: '   selectedRange.address);
});

CodePudding user response:

@RickKirkham answer helped point me in the correct direction. I had to add async to the main func and then I was able to do what was needed after Excel.Run

Eg:

Office.onReady(async function (info) {
    await Excel.run(async (context) => {
        var ws = context.workbook.worksheets.getActiveWorksheet()
        var rng = ws.getRange("A1")
        rng.load(["values"]);
        await context.sync();
        Input_Box_Client_Code.defaults.Value = rng.values[0][0];
        Init_InputBoxes(InputBoxs_ArrOfObjs);
    });
})
  • Related