1

Using the Excel Javascript API, I'd like to copy values and formatting from one rangeAreas object to another with equal dimensions. According to the docs, copyFrom should work the same with rangeAreas as it does with ranges. But I'm getting an error:

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

I expect this to write values, formats, etc. from cells B8 & B10 to 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();
  });

I have also tried without success:

  • adding more or fewer context.sync()s
  • adding optional params to copyFrom to override defaults

I am using MS365 v2407 and the Excel JS API v1.16

2
  • I can reproduce this. If you don't get an answer from the community in a couple of days, try filing a bug on the office-js repo. Commented Aug 14, 2024 at 22:19
  • I wonder what precisely is meant by this phrase in the docs: "When the source RangeAreas has multiple ranges, their form must able to be created by removing full rows or columns from a rectangular range." It escapes me what precisely is meant by this condition. Commented Aug 30, 2024 at 13:17

1 Answer 1

0

I think, CopyFrom only works when we copy single or multiple Range object to RangeArea object or vice versa

I tried the below sample and it worked for me. Maybe RangeArea.CopyFrom(RangeArea,..) have no support in officeJs API yet.

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

May be you can raise the support ticket in microsoft developer community

sample code

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.