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
670 stars 96 forks source link

Office.File.closeAsync() does not close XLSM file containing a Form in the VBAProject on a Windows host #2998

Open ruud-coder opened 1 year ago

ruud-coder commented 1 year ago

Office.File.closeAsync() works fine when the source document is an XLSX file, but when the source document is an XLSM file and on a Windows host, Office.File.closeAsync() does not work. That means the source document stays open (even though the AsyncResultStatus reports back as "Succeeded"). As the maximum number of open files is 2, this results in an error message upon the next autosave event.

RuizhiSunMS commented 1 year ago

@ruud-coder Thanks for reporting this. Usually, we suggest one submit his/her issue in the format and one can the format when creating issue in this channel. Especially, please provide detailed reproducing steps which can reproduce the issue constantly, that would be very helpful for us to troubleshoot.

davidchesnut commented 1 year ago

Hi @ruud-coder, thanks for letting us know about this. If you have a small code sample to reproduce this behavior (similar to the getSliceAsync sample near bottom of article here) that would be super helpful. Thanks!

ruud-coder commented 1 year ago

Hoi David, it's exactly the getSliceAsync you refer to that triggers the issue. I created a Promise to return the current Excel document:

    function getFilePromise() {
        return new Promise(resolve => {
            Office.context.document.getFileAsync(
                Office.FileType.Compressed,
                resolve
            );
        });
    }

    file = await getFilePromise();

now pass file.value to getSliceAsync and it triggers the issue, except.. the XLSM file needs to contain a Form (in the VBAProject) to trigger the issue. I added this to the issue title.

To create an Excel file that triggers the issue:

Note: on a Mac host, the issue does not occur.

davidchesnut commented 1 year ago

Hi @ruud-coder, thanks I'm able to repo this issue. @yaweizhu-henson can you help with this issue? Interestingly when I test this, it will work, then fail, then work, and repeat this pattern.

ruud-coder commented 1 year ago

Correct, same behaviour here. My understanding is the failure closes the file. Which is why you get the “flipping” behaviour work, fail, work, fail, …

gingerjia commented 1 year ago

@ruud-coder thanks for reporting the issue! We can repro the issue and reported a bug (7326407) to track it. Could you share more info about the impact to help us to priority the issue? Thanks!

ruud-coder commented 1 year ago

@gingerjia on the short run the issue is quite disturbing as we are moving a business critical application from the VBA world to the Javascript world. For that reason the current situation is we are using it with XLSM files that contain forms. However in about half a year I don't believe we'll still be using XLSM files.

I don't have a good workaround: within the javascript code I can catch the exception and retry, however a save initiated by the user or an autosave event triggered by Excel I cannot catch... (these fail as well when a file handler is still open)

gingerjia commented 1 year ago

@ruud-coder really sorry for the inconvenience! I have updated the detail impact to the bug and will update here if have any progress! Thanks again for your help to improve our quality!