Convert doc file with macros to docx using C#

Hi everyone,

I am evaluating GroupDocs conversion library for my project.

I am interested to convert document/ppt/excel back to same format but for the docx/pptx/xlsx target formats.
Basically I want the converted file free of macros.

But when I test converting a simple document with macro to docx, I get an exception like these:

System.InvalidOperationException: This document contains macros (VBA project) and you are attempting to save it in a Macro-Free format. Such document will be invalid if created. You need to either save it in a Macro-Enabled format (.DOCM or .DOTM) or remove macros before saving using the Document.RemoveMacros method.
at .()
at .( ? )
at Aspose.Words.Document.(Stream , String , SaveOptions )
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)
at ? . ???(Stream )
at . ???(Stream , SaveOptions )
at GroupDocs.Conversion.Handler.ConversionHandler.[T]( , SaveOptions )
at GroupDocs.Conversion.Handler.ConversionHandler.[T]( , SaveOptions )
at GroupDocs.Conversion.Handler.ConversionHandler.Convert[T](Stream fileStream, LoadOptions loadOptions, SaveOptions saveOptions)
at GroupDocs.Conversion.Handler.ConversionHandler.Convert[T](Stream fileStream, SaveOptions saveOptions)
at DocConversion.Conversion.ConvertToWordFromStreamToFile() in C:\workspace\DocConversion\DocCoversion\Conversion.cs:line 312
at DocConversion.Program.Main(String[] args) in C:\workspace\DocConversion\DocCoversion\Program.cs:line 130

But I cannot find such RemoveMacros method available, how I can use GroupDocs conversion SDK to convert file from doc/docm/docx, regardless with macro or not, to docx ?

Thanks!

@ledmirage,

Thank you for your inquiry. In order to further investigate the issue, we need to know that which version of the API you are evaluating (integrated in your project)? Also, please share the problematic files and sample code with us.

Hi,

You an find the sample doc here

Its basically a very simple doc with macro. When trying to convert to docx it throws exception.

below is the code snippet for the doc conversion:

`
        // Instantiating the conversion handler from custom common class
        ConversionHandler conversionHandler = Common.getConversionHandler();

        // Setting the saving file type
        WordsSaveOptions.WordsFileType saveFileType = WordsSaveOptions.WordsFileType.Docx;
        switch (Common.outputFileExtension.ToLower())
        {
            case ".doc":
                saveFileType = WordsSaveOptions.WordsFileType.Doc;
                break;
            case ".docm":
                saveFileType = WordsSaveOptions.WordsFileType.Docm;
                break;
            case ".docx":
                saveFileType = WordsSaveOptions.WordsFileType.Docx;
                break;
            case ".dot":
                saveFileType = WordsSaveOptions.WordsFileType.Dot;
                break;
            case ".dotm":
                saveFileType = WordsSaveOptions.WordsFileType.Dotm;
                break;
            case ".dotx":
                saveFileType = WordsSaveOptions.WordsFileType.Dotx;
                break;
            case ".rtf":
                saveFileType = WordsSaveOptions.WordsFileType.Rtf;
                break;
            case ".txt":
                saveFileType = WordsSaveOptions.WordsFileType.Txt;
                break;
            case ".odt":
                saveFileType = WordsSaveOptions.WordsFileType.Odt;
                break;
            case ".ott":
                saveFileType = WordsSaveOptions.WordsFileType.Ott;
                break;
            default:
                saveFileType = WordsSaveOptions.WordsFileType.Docx;
                break;

        }

        // read input document as a stream
        FileStream fileStream = new FileStream( Common.inputGUIDFile, FileMode.Open, FileAccess.Read);

        // Returns the converted Word Processing Documents as File Path using stream input.
        var convertedDocumentStream = conversionHandler.Convert<String>(fileStream, new WordsSaveOptions { OutputType = OutputType.String, ConvertFileType = saveFileType, CustomName = Common.outputFileName });

        fileStream.Close();`

Thanks

@ledmirage,

Thank you for sharing the sample code and file. Can you please also tell us, which version of the API you integrated in your project?

i am not too sure how to check the version, but it should be pretty recent

below is the DLL I used and it’s md5 hash:

2269af2252b4be4b24521211ac160e5e GroupDocs.Conversion.dll

@tse.erh,

This is how you can see which version of the API you are evaluating:

  • Open project in visual studio
  • Go to solution explorer
  • In references, right click on GroupDocs.Conversion and press properties

You can see DLL version there. Please find the attached screenshot for further details. If you are using any other IDE. Please let us know, we’ll help you out in finding the DLL version.
DLL Properties.JPG (138.0 KB)

screenshot here

@tse.erh,

We have successfully reproduced this issue at our end. Hence, it’s been logged in our internal issue tracking system with ID:CONVERSIONNET-2180. As we get any update from the concerned team, you shall be notified. Your patience shall be appreciated.

@tse.erh,

We got an update from the concerned team. Your issues shall be resolved in 17.11 version of the API and the release is expected in November. As it gets on-board, we’ll apprise you.

Thanks for the update.

@tse.erh,

You’re welcome.

@tse.erh,

Your reported issue CONVERSIONNET-2180 is resolved. Please download the latest release from here and share your feedback.