Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting RangeView.numberFormat errors if the visibleView is 1 cell #4452

Open
ChrisWRWX opened this issue May 14, 2024 · 2 comments
Open

Setting RangeView.numberFormat errors if the visibleView is 1 cell #4452

ChrisWRWX opened this issue May 14, 2024 · 2 comments
Assignees
Labels
Area: Excel Issue related to Excel add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback

Comments

@ChrisWRWX
Copy link

ChrisWRWX commented May 14, 2024

Provide required information needed to triage your issue

When trying to set the numberFormat of a visibleView that contains only 1 cell, the follow error is produced:

RichApi.Error / InvalidArgument / "The argument is invalid or missing or has an incorrect format."

Your Environment

  • Platform [PC desktop, Mac, iOS, Office on the web]: PC Desktop
  • Host [Excel, Word, PowerPoint, etc.]: Excel
  • Office version number: Version 2406
  • Operating System: Windows 10
  • Browser (if using Office on the web): N/A

Expected behavior

Setting the numberFormat should behave the same for a range of 1 cell as for larger ranges.

Current behavior

When getVisibleView() reduces the visible range to a single cell, setting the numberFormat no longer works.

Steps to reproduce

This works as expected:

  • Add some data and set a filter such that more than 1 row remains.
  • Run code below.
  • The two cells are set to Text format.

image

// Sample for Script Lab
$("#run").on("click", () => tryCatch(run));

async function run() {
  await Excel.run(async (context) => {
    // adjust to not include header and only get visible cells
    const range = context.workbook
    .getSelectedRange()
    .getOffsetRange(1, 0)
    .getVisibleView();

    // Set 2 cells
    range.numberFormat = [["@"],["@"]];

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

This does not work:

  • Add some data and set a filter such that only 1 row remains.
  • Run code below.
  • An error is thrown.

image

// Sample for Script Lab
$("#run").on("click", () => tryCatch(run));

async function run() {
  await Excel.run(async (context) => {
    // adjust to not include header and only get visible cells
    const range = context.workbook
    .getSelectedRange()
    .getOffsetRange(1, 0)
    .getVisibleView();

    // Set 1 cell
    range.numberFormat = [["@"]];

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

Context

This causes an unpredictable error that only surfaces when a visible range is filtered down to a single cell.

Copy link
Contributor

Thank you for letting us know about this issue. We will take a look shortly. Thanks.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label May 14, 2024
@XuanZhouMSFT
Copy link

Thanks for reporting this issue regarding RangeView.numberFormat. It has been put on our backlog using #8989182. We will let you know once we fix it.

@XuanZhouMSFT XuanZhouMSFT self-assigned this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Excel Issue related to Excel add-ins Needs: attention 👋 Waiting on Microsoft to provide feedback
Projects
None yet
Development

No branches or pull requests

3 participants