将工作表中的数据放入任务窗格

发布于 2025-01-10 13:30:51 字数 460 浏览 2 评论 0原文

我有一个任务窗格和我想从工作表中填写的字段之一。

如何在 Office 任务窗格启动期间访问工作表中的数据?

示例:

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";

})

给出错误Context未定义。

如何加载一些数据并在启动时将其发送到任务窗格?

一个简单的例子是,我有一个下拉列表,我想用列字母填充它,但只能从 usedrange 中填充。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦中楼上月下 2025-01-17 13:30:51

您似乎正在尝试使用 Excel.RequestContext 对象。在调用它之前,您需要获得对它的引用。建议的方法是调用 Excel.run。它将自动创建 context 对象并将其传递给回调。这是一个例子。

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

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);
});
笔芯 2025-01-17 13:30:51

@RickKirkham 的回答帮助我指明了正确的方向。我必须将 async 添加到主函数中,然后我才能执行 Excel.Run 之后需要的操作,

例如:

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);
    });
})

@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);
    });
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文