使用 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()
scopyFrom
添加可选参数以覆盖默认值我正在使用 MS365 v2407 和 Excel JS API v1.16
我认为,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();
});
也许您可以在微软开发者社区中提出支持票