Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Aug 29, 2019 8:29 am

Is it possible to open a .doc or .docm file with all macros disabled? Is this a feature available in the paid version only, or in all versions?

My question actually applies to all Office files (.doc/.docm, .xls/.xlsm, .ppt/.pptm) but I don't want to spam all the forums with the same question.

martin.bonner
 
Posts: 1
Joined: Thu Aug 29, 2019 7:29 am

Thu Aug 29, 2019 9:29 am

Hi Martin,

Thanks for your inquiry.
For .doc/.docm file, you could use Spire.Doc and following code to delete Marcos.
Code: Select all
            //Initialize a Document object
            Document document = new Document();
            //Load the Word document
            document.LoadFromFile("Input.docm");

            //If the document contains macros, remove them from the document
            if (document.IsContainMacro)
            {
                document.ClearMacros();
            }           
            //Save the document
            document.SaveToFile("Output.docm", FileFormat.Docm);   


For .xls/.xlsm file, you could use Spire.XLS and following code:
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"F:\testing\xls test form\sample document\Macro test.xls");
            //clear the marcos
            workbook.HasMacros = false;
            workbook.SaveToFile("result.xlsx",ExcelVersion.Version2013);


For .ppt/.pptm file, sorry that at present there is no method to delete Marcos in Spire.Presentation. We will consider adding the new feature in our future upgrade.

Note if you want to use Spire.Doc, Spire.XLS and Spire.Presentation in same project, you need to download our Spire.Office and reference corresponding dlls(Spire.License.dll, Spire.Doc.dll, Spire.Pdf.dll, Spire.Xls.dll, Spire.Common.dll, Spire.Presentation.dll) in your project.
And new feature will be included in commercial version firstly. We will let you know once the hotfix which includes the new feature is released.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Sep 30, 2019 10:06 am

Hi Martin,

Glad to inform you the new feature of removing Macros in ppt file has been implemented. Welcome to download and use Spire.Office Platinum (DLL Only) Version:4.9.2.
Our website link: https://www.e-iceblue.com/Download/down ... t-now.html
NuGet link: https://www.nuget.org/packages/Spire.Office/

Sample code:
presentation.DeleteMacros();

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Oct 17, 2019 9:09 am

Hi,

Greetings from E-iceblue.
Do you use the hotfix? Has your issue been resolved?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc