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

Error when adding rows to table using Excel JS library with a specific sheet #4991

Open
buzzo123 opened this issue Oct 21, 2024 · 4 comments
Assignees
Labels
Area: Excel Issue related to Excel add-ins Status: in backlog Issue is being tracked in the backlog but timeline for resolution is unknown

Comments

@buzzo123
Copy link

Description:
I am encountering an issue when attempting to add rows to a table using the Excel JS library while a specific sheet is opened. The issue persists only with this particular sheet, which is attached.

Environment:

  • Excel version: Microsoft® Excel® for Microsoft 365 MSO (Version 2409 Build 16.0.18025.20030) 64-bit
  • Office.js version: "@microsoft/office-js": "^1.1.94"
  • Platform: Windows 11

The following code triggers the error:

async function createTable() {
  await Excel.run(async (context) => {
    context.workbook.worksheets.getItemOrNullObject("Sample").delete();
    const sheet = context.workbook.worksheets.add("Sample");

    const expensesTable = sheet.tables.add("A1:D1", true /*hasHeaders*/);
    expensesTable.name = "ExpensesTable";

    expensesTable.getHeaderRowRange().values = [["Date", "Merchant", "Category", "Amount"]];

    expensesTable.rows.add(null /*add at the end*/, [
      ["1/1/2017", "The Phone Company", "Communications", "$120"],
      ["1/2/2017", "Northwind Electric Cars", "Transportation", "$142"],
      ["1/5/2017", "Best For You Organics Company", "Groceries", "$27"],
      ["1/10/2017", "Coho Vineyard", "Restaurant", "$33"],
      ["1/11/2017", "Bellows College", "Education", "$350"],
      ["1/15/2017", "Trey Research", "Other", "$135"],
      ["1/15/2017", "Best For You Organics Company", "Groceries", "$97"]
    ]);

    sheet.getUsedRange().format.autofitColumns();
    sheet.getUsedRange().format.autofitRows();

    sheet.activate();

    await context.sync();
  });
}

Steps to Reproduce:

  1. Open the attached sheet in Excel.
  2. Run the above script to add rows to the table.
  3. Observe the error in the console.

Console Error Message:

[ERROR]: Error:
{
    "stack": "RichApi.Error: There was an internal error while processing the request.\n    at new n (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:25:265694)\n    at r.processRequestExecutorResponseMessage (https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:25:330663)\n    at https://appsforoffice.microsoft.com/lib/1/hosted/excel-win32-16.01.js:25:328724",
    "message": "There was an internal error while processing the request.",
    "name": "RichApi.Error",
    "code": "GeneralException",
    "traceMessages": [],
    "innerError": null,
    "debugInfo": {
        "code": "GeneralException",
        "message": "There was an internal error while processing the request.",
        "errorLocation": "TableRowCollection.add",
        "statement": "var add2 = rows.add(...);",
        "surroundingStatements": [
            "...",
            "add1.name = ...;",
            "var headerRowRange = add1.getHeaderRowRange();",
            "// Instantiate {headerRowRange}",
            "headerRowRange.values = ...;",
            "var rows = add1.rows;",
            "// >>>>>",
            "var add2 = rows.add(...);",
            "// <<<<<",
            "var usedRange = add.getUsedRange();",
            "// Instantiate {usedRange}",
            "var format = usedRange.format;",
            "format.autofitColumns();",
            "var usedRange1 = add.getUsedRange();",
            "..."
        ],
        "fullStatements": [
            "Please enable config.extendedErrorLogging to see full statements."
        ]
    },
    "httpStatusCode": 500
}

Expected Result:
The rows should be added successfully to the table on the specified sheet.

Actual Result:
The script fails with a GeneralException (HTTP 500 error) at TableRowCollection.add.

Questions:

  • Can you help me identify why this error appears?
  • Why would an error in a sheet be related to a new table creation in another sheet?

Additional Information:
I have attached the problematic sheet file for reference.

error_sheet.xlsx

@microsoft-github-policy-service microsoft-github-policy-service bot added the Area: Excel Issue related to Excel add-ins label Oct 21, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: attention 👋 Waiting on Microsoft to provide feedback label Oct 21, 2024
Copy link
Contributor

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

@buzzo123
Copy link
Author

I just wanted to highlight that this is an urgent matter because our users are experiencing malfunctions, and they are unable to identify the specific sheets causing the problem. This is impacting their workflows significantly. A timely resolution would be greatly appreciated as it directly affects their ability to work efficiently.
Thanks again for your support!

@qinliuMSFT
Copy link
Member

qinliuMSFT commented Oct 22, 2024

Thank you for reporting this issue, I can repro it. It has been put on our backlog # 9468822, the team will investigate and we will reply to you as soon as there is any progress. Thank you for your patience.

Meanwhile, could you please share the name of the add-in? Or you can provide the scale of affected users, it will help us re-prioritize this bug.

@qinliuMSFT qinliuMSFT added Status: in backlog Issue is being tracked in the backlog but timeline for resolution is unknown and removed Needs: attention 👋 Waiting on Microsoft to provide feedback labels Oct 22, 2024
@buzzo123
Copy link
Author

The add-in is a custom software solution that helps users create forms and retrieve data from a database. It is currently not available in the public store but is distributed through the Microsoft 365 Admin Center for our customers' organizations. After retrieving data with the add-in, users often customize the sheet, and I suspect this customization is responsible for the bug, causing all subsequent table creation via Excel.js to fail. However, I am unable to pinpoint exactly why this happens.

This issue is affecting multiple users across different organizations, making it difficult for them to complete their tasks effectively. We would appreciate any assistance in prioritizing this bug, as it’s having a significant impact on user productivity.

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 Status: in backlog Issue is being tracked in the backlog but timeline for resolution is unknown
Projects
None yet
Development

No branches or pull requests

2 participants