I evaluated your issue using your template file with Aspose.Cells APIs. I then tested your scenario/case in MS Excel manually by opening the XLS file into it and then re-save to XLSX (Excel Workbook). I found MS Excel prompts error message that it won’t save VB project, so the output XLSX file will be macro-free workbook. Aspose.Cells does show the same behavior, so it is not an issue with the APIs.
Let us know if you still have any issue, we will check it soon.
Indeed my test was not logical, I should have saved my file in XSLM.
I redid my scenario, after saving in XSLM, the macro seems to have been removed, what I do not understand, however, is that it is a macro that is not present in the original document.
You are right this time. Please notice, I am able to reproduce the issue as you mentioned by converting your template XLS file to XLSM file format. The macros seems removed. I have logged a ticket with an id “CELLSNET-48359” for your issue. We will look into it soon.
Once we have an update on it, we will let you know.
This is to notify you that the issue has been resolved. After performing QA and incorporating other extensions and fixes, we will provide you the fixed version within the next few days.
The issues you have found earlier (filed as CELLSNET-48359) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao
Please notice, the issue is reproduced with latest version/fix as you mentioned by converting your template XLS file to XLSM file format. The macros seems not working and no more in the output XLSM. I have logged a new ticket with an id “CELLSNET-49117” for your issue. We will look into it soon.
Once we have an update on it, we will let you know.
@ISIWARE,
Xlsx file can not contain macro codes, so if you save the file as xlsx file, macro codes are removed.
So if you want to make the macro works, please save it as xlsm file.
Please note, if you save the workbook (which is loaded from the XLS template file) to XLSM file directly, the macro will be available in the resultant XLSM file. However, in your code, if the Workbook was saved as XLSX file first, then in such kind of situation, the macro in the Workbook object will be removed while saving, so later when saving this Workbook object to XLSM file again, there is no macros to be saved, so the functions using the macros cannot work any more in the resultant XLSM file.
In short, this code works fine:
Workbook workbook = new Workbook("e:\\test2\\OriginalDocument.xls");
workbook.Save("e:\\test2\\out12.xlsm", SaveFormat.Xlsm);
but this code does not work, I mean macros are not working anymore in output XLSM:
Workbook workbook = new Workbook("e:\\test2\\OriginalDocument.xls");
workbook.Save("e:\\test2\\out1.xlsx", SaveFormat.Xlsx);
workbook.Save("e:\\test2\\out12.xlsm", SaveFormat.Xlsm);
I’ve still got a problem. “OriginalDocument.xls” is the original doc with macro, “outputDocument.xlsm” is the doc create by saving the original doc using the code in “SavingFiles.cs” and “excelDocument.xlsm” is the doc create by saving the original doc in xlsm with Excel.
Open “OriginalDocument.xls”, click on the button surrounded by red in img1.png, click on the button surrounded by bleu in img1.png, and click on the button surrounded by green in img1.png. It will create a new page with a heading (img2.png).
It’s works with the “OriginalDocument.xls” and “excelDocument.xlsm” but not with “outputDocument.xlsm”.
The test was performed with Aspose Cells version 21.10.0.
All docs, images and C# code used are in the attached zip files.file.zip (213.4 KB)
@ISIWARE,
Thank you for providing more information. We have observed the issue and logged it into our database for further investigation. You will be notified here once any update is ready for sharing.
This issue is logged as: CELLSNET-49654 - Macros are not working after converting XLS to XLSM
This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-49654”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.
The issues you have found earlier (filed as CELLSNET-49654) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao