Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Dec 20, 2022 4:31 pm

I have Spire.XLS version 10.5.7 and .net 6
I have a excel file with extension .xlsm and the file contains Maros with "VBA Code"
I can open the file, Edit, then close it with no Issues

here is the code:

Code: Select all

xlWorkBook = new Workbook();
xlWorkBook.LoadFromFile(filePath);
xlWorkBook.CalculateAllValue();
xlWorkBook.Save();
xlWorkBook.Dispose();



If I try to upgraded Spire.xls version to "12.11.3" without changing a single line of code, All the Maros "VBA Code" get deleted after save,

this issue exsits since Spire.XSL Version 10.11.2 and until the latest version

amarghani
 
Posts: 2
Joined: Tue Dec 20, 2022 4:18 pm

Wed Dec 21, 2022 2:12 am

Dear Ahmed,

Thanks for your inquiry.
I reproduced your issue on my side. A ticket with ID SPIREXLS-4365 has been created in our bug tracking system to further investigate the issue. We will share the notification with you as soon as the issue is resolved. Apologize for the inconvenience caused.
Besides, I have confirmed if change your code to specify the Xlsm format when saving, the issue will not happen. Maybe you can use it as a temporary workaround.
Code: Select all
Workbook xlWorkBook = new Workbook();
xlWorkBook.LoadFromFile("test.xlsm");
xlWorkBook.CalculateAllValue();
//Specify the Xlsm format
xlWorkBook.SaveToFile("result.xlsm", FileFormat.Xlsm);
xlWorkBook.Dispose();

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Wed Dec 21, 2022 2:26 pm

Thank you for your fast response, I am so happy that you are able to reproduce the issue in your end.

I have tried the work around you proposed, it fixes the issue of VBA code but it generated another Issue.

The protect function is not working properly , below is the code


Code: Select all
Workbook xlWorkBook = new Workbook();
xlWorkBook.LoadFromFile("test.xlsm");

foreach (Worksheet xlSht in xlWorkBook.Worksheets)
                {
                    xlSht.Protect(“12345”);
                }
xlWorkBook.CalculateAllValue();
//Specify the Xlsm format
xlWorkBook.SaveToFile("result.xlsm", FileFormat.Xlsm);
xlWorkBook.Dispose();



when I open “result.xlsm” with excel I see not all of the sheets has been protected using the password “12345”

these two issues together are show stopper for us and preventing us from upgrading to a newer version

amarghani
 
Posts: 2
Joined: Tue Dec 20, 2022 4:18 pm

Thu Dec 22, 2022 2:07 am

Dear Ahmed,

Thanks for your feedback.
I tested the protection function but didn’t reproduce your issue. Please provide your test.xlsm and result.xlsm, and tell us which sheet’s password is incorrect. Then we will do further investigation. Thanks in advance.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1187
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.XLS