gkosianenko's avatar
gkosianenko
Copper Contributor
Oct 29, 2025
Status:
New

The valuesAsJson method does not work as expected

Using the valuesAsJson method, I don't expect it to change the data.

Below is a simple code that copies an Excel range.
Running it, I expect to get an exact copy of the following range

 

document.getElementById("run").addEventListener("click", () => tryCatch(run));

async function run() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    const sourceRange = sheet.getRange("A2:C4");

    sourceRange.load({
      valuesAsJson: true,
    });

    await context.sync();

    const outputRange = sheet.getRange("A6:C8");

    outputRange.set({
      valuesAsJson: sourceRange.valuesAsJson,
    });

    await context.sync();
  });
}

/** Default helper for invoking an action and handling errors. */
async function tryCatch(callback) {
  try {
    await callback();
  } catch (error) {
    // Note: In a production add-in, you'd want to notify the user through your add-in's UI.
    console.error(error);
  }
}

 

But instead of the copy, I get the following result:

Please notice that cells B7 and C6 are not empty.

It seems to be a bug.

No CommentsBe the first to comment