rangeAreas 对象上的 copyFrom 抛出无效参数错误 - Javascript Excel

问题描述 投票:0回答:1

使用 Excel Javascript API,我想将值和格式从一个 rangeAreas 对象复制到另一个具有相同尺寸的对象。根据 the docs

copyFrom
rangeAreas
的作用应该与
ranges
的作用相同。但我收到错误:

RichApi.Error: The argument is invalid or missing or has an incorrect format.

我希望它将值、格式等从单元格 B8 和 B10 写入到 G8 和 G10:

  await Excel.run(async (context) => {
    let s = context.workbook.worksheets.getActiveWorksheet();
    let sourceRanges = s.getRanges("B8, B10");
    let destinationRanges = s.getRanges("G8, G10");
    sourceRanges.format.fill.color = "pink"; // this DOES work, so sourceRanges is somewhat functional
    await context.sync();
    destinationRanges.copyFrom(sourceRanges); // RichApi.Error: The argument is invalid or missing or has an incorrect format.
    await context.sync();
  });

我也尝试过,没有成功:

  • 添加更多或更少
    context.sync()
    s
  • copyFrom
    添加可选参数以覆盖默认值

我正在使用 MS365 v2407 和 Excel JS API v1.16

javascript excel office-js office-addins office365api
1个回答
0
投票

我认为,CopyFrom 仅在我们将单个或多个 Range 对象复制到 RangeArea 对象时才有效,反之亦然

我尝试了下面的示例,它对我有用。也许 RangeArea.CopyFrom(RangeArea,..) 在 OfficeJs API 中尚不支持。

await Excel.run(async (context) => {
      let s = context.workbook.worksheets.getActiveWorksheet();
      let sourceRanges = s.getRange("B8:B10");
      let destinationRanges = s.getRanges("G8,G10");
      sourceRanges.format.fill.color = "pink"; // this DOES work, so sourceRanges is somewhat functional
      await context.sync();
      destinationRanges.copyFrom(sourceRanges,Excel.RangeCopyType.all); // RichApi.Error: The argument is invalid or missing or has an incorrect format.
      await context.sync();
    });

也许您可以在微软开发者社区中提出支持票

sample code

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.