Office-js: getFileAsync() does not support .xlsm format

Created on 29 Mar 2019  路  4Comments  路  Source: OfficeDev/office-js

TL;DR Are .xlsm files containing macros not supported? This seems to be the case but I have not seen a definitive answer.

My add-in sends the file contents to the server, where it is saved to the filesystem. This has been working fine until we started using XLSM files that contain macros. When these files are sent, the resulting file on the server has a smaller size than the original. Opening the file that's on the server fails with an error: "_Excel cannot open the file 'foo.xlsm' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file._"

It seems that it's dropping the macros and saving it in XLSX format. Two pieces of supporting evidence:

  1. The smaller file is the same size as the original file when intentionally saved without macros as an .xlsx. Example: Original _foo.xlsm_ is 2405 KB. Server version of _foo.xlsm_ is 2338 KB. If I save the original as an .xlsx, it prompts me that it will remove any macros. I accept, and resulting _foo.xlsx_ is 2337 KB. Virtually same size.
  2. I can simply rename the ostensibly corrupted _foo.xlsm_ to _foo.xlsx_, and it opens just fine. Whereas taking an .xlsx file and renaming it to ".xlsm" causes a file format error like the one above. This suggests it's truly in XLSX format underneath.

I'll work on distilling a working example I can share, but it may take some time. In the meantime, perhaps someone can definitively say whether XLSM is not supported? If it is not, this poses a significant problem for me.

Environment

  • Platform [PC desktop, Mac, iOS, Office Online]: Desktop
  • Host [Excel, Word, PowerPoint, etc.]: Excel
  • Office version number: Office 365 ProPlus, Version 1803, Build 9126.2356
  • Operating System: Windows 10 Enterprise, Version 1709, Build 16299.967

Most helpful comment

@JuaneloJuanelo That is not good answer. @cawise clearly stated this is an internal application. There should be a way to mark a document as trusted or trust this type of upload somehow. Office.js is years into development and still far behind the old COM and VBA. It even took months just to respond to this question.

All 4 comments

Hi @cawise
Could you please share us your scenario for using XLSM file with Office.JS?
An XLSM file is a VBA macro-enabled workbook, however, VBA is not be able to across platform.
Is that possible for you use office.js to replace VBA macro?

Hi @lumine2008,

Rewriting the macro functionality using Office.js is an option I鈥檓 looking into but was hoping to avoid even if possible, as this may require significant additional work and delay.

Here is my scenario. The add-in is internal to my organization. My dev team is provided a large spreadsheet used for financial analysis and forecasting, and we add bindings to many key data points in this document. The add-in allows our users to send all of these data points directly from Excel to the internal business line application we maintain. It also sends the entire file itself so it can later be downloaded in the exact state it was when sent.

This time the spreadsheet the users provided is an .xlsm containing macros that they rely upon, though I don鈥檛 yet know what exactly these macros do. I was expecting that the file would be sent in its entirety just as it appears on disk, but it appears to be converting to .xlsx, thus removing the macros. I realize VBA macros are not cross-platform, but this is not an issue for us as Windows desktop is the only platform our organization currently uses and supports.

Is there no way to preserve the .xlsm format and its macros? Am I correct that .getFileAsync() is designed to strip them out?

Thanks.

this is by design we do not support adding files with macros on such methods due to security issues.

@JuaneloJuanelo That is not good answer. @cawise clearly stated this is an internal application. There should be a way to mark a document as trusted or trust this type of upload somehow. Office.js is years into development and still far behind the old COM and VBA. It even took months just to respond to this question.

Was this page helpful?
0 / 5 - 0 ratings