OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
690 stars 95 forks source link

Issue with 'await context.sync()' Failing for customXmlParts in Excel for iPad When File is Unsaved #3936

Open t-miyake opened 11 months ago

t-miyake commented 11 months ago

Provide required information needed to triage your issue

I am experiencing an issue with Excel for iPad where 'await context.sync()' related to customXmlParts fails when the file is not saved. Specifically, it results in the following error: "GeneralException: There was an internal error while processing the request."

This error does not occur in Excel Online, Windows, or other versions; they operate normally. Notably, it also works correctly on Safari.

Therefore, I suspect the issue is specific to Excel for iPad. I speculate that this problem may have started occurring in version 2.8.0 or later.

Your Environment

Expected behavior

'await context.sync()' is executed successfully.

Current behavior

The following error: "There was an internal error while processing the request."

Steps to reproduce

I have created the following simple sample.

Excel Online Both the sheet name and the number of customXmlParts are successfully obtained. Excel Online

Excel for iPad The number of customXmlParts cannot be obtained, resulting in an error. If it is a saved file, not a newly created file, you can successfully get the number of customXmlParts. If it is a saved file, it is normal even if the file is empty. iPad

Office.onReady().then(async () => {
    let textOutput = "";

    try {
        await Excel.run(async (context) => {
            const sheets = context.workbook.worksheets;
            sheets.load("items/name");
            await context.sync();

            const sheetNames = sheets.items.map(sheet => sheet.name);
            textOutput += sheetNames.join("\n") || "No sheets found.\n";
        });
    } catch (error) {
        textOutput += "An error occurred: " + error + "\n";
    }

    textOutput += "\n\n";

    try {
        await Excel.run(async (context) => {
            const customXmlParts = context.workbook.customXmlParts;
            const filteredXmlParts = customXmlParts.getByNamespace("http://schemas.noraneko.co.jp/jsons/1.0");
            const numberOfPartsInNamespace = await filteredXmlParts.getCount();
            await context.sync();

            textOutput += `Number of custom XML parts in the namespace: ${numberOfPartsInNamespace.value}`;
            if (numberOfPartsInNamespace.value === 0) {
                textOutput += " (No custom XML parts found in the namespace)";
            }
        });
    } catch (error) {
        textOutput += "An error occurred: " + error;
    }

    document.getElementById("text").innerText = textOutput;
});
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
</head>
<body>
    <div>
        <p id="text"></p>
    </div>
    <script src="taskpane.js"></script>
</body>
</html>

Link to live example(s)

The URL of the manifest file for the above sample is https://outlook.addin.app/excel/sample/ExcelTaskpaneAddin.xml

microsoft-github-policy-service[bot] commented 11 months ago

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

t-miyake commented 11 months ago

Sorry for the omission earlier. I've now updated the "Provide required information needed to triage your issue" section with the necessary details.

penglongzhaochina commented 11 months ago

Thanks for reporting this issue. We can reproduce this issue.

It has been put on our backlog<Bug#8612235> for internal track. We will keep track of this issue and let you know if there are any updates.