locked
How to implement SaveAs option using primary office interop assemblies in vc++ or native c++?? RRS feed

  • Question

  • HI, Everyone..

    I am working  on module to convert Doc/Docx to word 2003 XML document using c++..But i had great problem writing native c++ code for conversion process..I had come across interop assemblies which easy the process instead of writing prolonged code..But interop assemblies have support to .NET and C#..i have seen so many examples which have implemented this task using c#..is there any existing examples in C++ to implement this task??..This is my sample code..please correct it..i am not getting proper output:

    void SaveXml();
        {
            String fn = @"C:\Users\zbook\Desktop\Track test.docx";
            String fn_xml = @"C:\Users\zbook\Desktop\Track test3.xml";
            Microsoft::Office::Interop::Word::Application app = new Microsoft::Office::Interop::Word:: Application();
            Word::Documents docs = app->Documents;
            Word::Document doc = docs->Open(fn, ReadOnly:true);
            //bool b = doc.TrackFormatting; // for some reason this line bombs
            doc->SaveAs2(fn_xml, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXML);
            doc->Close(false);
            Marshal->ReleaseComObject(doc);

            // now open up fn_xml ... and do whatever

            app->Quit(false);
            Marshal->ReleaseComObject(docs);
            Marshal->ReleaseComObject(app);

        }

    • Moved by KareninstructorMVP Thursday, September 18, 2014 12:23 PM Moved from VB.NET forum
    Thursday, September 18, 2014 11:30 AM

All replies

  • This question should be posted or moved by a moderator to the Visual C++ forum:

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vcgeneral


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, September 18, 2014 12:19 PM
  • HI, Everyone..

    I am working  on module to convert Doc/Docx to word 2003 XML document using c++..But i had great problem writing native c++ code for conversion process..I had come across interop assemblies which easy the process instead of writing prolonged code..But interop assemblies have support to .NET and C#..i have seen so many examples which have implemented this task using c#..is there any existing examples in C++ to implement this task??..This is my sample code..please correct it..i am not getting proper output:

    void SaveXml();
        {
            String fn = @"C:\Users\zbook\Desktop\Track test.docx";
            String fn_xml = @"C:\Users\zbook\Desktop\Track test3.xml";
            Microsoft::Office::Interop::Word::Application app = new Microsoft::Office::Interop::Word:: Application();
            Word::Documents docs = app->Documents;
            Word::Document doc = docs->Open(fn, ReadOnly:true);
            //bool b = doc.TrackFormatting; // for some reason this line bombs
            doc->SaveAs2(fn_xml, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXML);
            doc->Close(false);
            Marshal->ReleaseComObject(doc);

            // now open up fn_xml ... and do whatever

            app->Quit(false);
            Marshal->ReleaseComObject(docs);
            Marshal->ReleaseComObject(app);

        }

    Friday, September 19, 2014 6:31 AM