locked
Interaction with Microsoft Office Applications (Excel, Word, etc.) within an App

    Question

  • Hi

    I'm rewriting a programm into a windows app. this program (document management program) has created office documents using the COM Application interface (a.e. Word.Application) and has done some interaction with the office programm to modify the documents before editing.

    Now in the app, I have no idea how to do this. How can I lunch office from the app and interact with it?

    My gool is actually

    - Create an instance of Office component (word, excel, etc.)

    - Interact with office and do some document changes (like mailmerge)

    - Raise the new document in office.

    I did not find any office libraries that are cabable to be used in a windows 8 app.

    Using Office Web Apps is not really the solution. Document Creation on the server side is not possible using office application. I'm even not willing to use third party solutions.

    I'm able to start the associated application with the editing files, this is not my goal.

    Actually the main point is, that the user has installed office on his desktop and the programm should interact with this application.

    Thanks in advance

    Khamis




    • Edited by Khamis Diab Tuesday, January 01, 2013 12:57 AM
    Tuesday, January 01, 2013 12:39 AM

Answers

  • Hi Khamis,

    The UI Design for Windows Store apps forum is for discussion of designing the UI of a Windows Store app. Questions about using Office components should go to the appropriate Office Development forums. Questions about implementing Windows Store apps should go to the appropriate Windows Store apps forum for the language and UI layer that you are using.

    By design, Windows Store apps are isolated from each other and cannot interact in the way you want: there is no supported way for a Windows Store app to communicate with or automate another application on the system.

    Windows Store apps cannot load arbitrary COM objects, such as the Office objects you are using in your sample code. They can load only a few specific Windows-provided objects or registration free objects installed with the application.

    It would be possible to write a component which could open, manipulate, and save a Word document, but it couldn't call an external instance of Word to do so. If the 3rd party components you mention work in Windows Store apps then this is what they must be doing.

    Any questions about whether Word provides such a component would be best asked in the Word forums, but I don't believe such a component currently exists.

    --Rob

    Thursday, January 03, 2013 1:42 AM
    Owner

All replies

  • What's kind of your app to launch and interact with Office programmatically?

    If it's a Windows Store app, there is no interface to achieve your goals mentioned above.

    If it's a Desktop app, you can leverage Office object model which is a complete set of APIs exposed by Office. For more details, please visit Object model reference (Word 2013 developer reference) and other references for Excel etc.


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 02, 2013 6:18 AM
    Moderator
  • Hi Robin 

    thank you for your reply. As I described above my application should create a document using mail merge and open it in office. my desktop application already do this. below is a snap of my code.

    Actually it es even not possible to do the same thing interactive in a webservice, because Office is not background cabable (without console). So the easiest way would be to do the same in my windows store app. Office Web Apps would be probably a solution, but this is for me unpracticable solution. With a third party solutions like "TxTextcontrol Server" or "Aspose" it would be possible, but I'm not interested in those solutions. The way it worked until now is actually very cabable.

    Are there any plans by office to make itself "windows store app cabable"?

    // start word
                Word.Application word = null;
                try
                {
                    var glob = new Word.Global();
                    if (glob.Application != null)
                        word = glob.Application;
                }
                catch
                {
                    // ignore, no instance is running
                }
                if (word == null)
                    word = new Word.Application();
                try
                {
                    var wordDoc = word.Documents.Add(provider.TemplatePath, Type.Missing, Type.Missing, false);
                    try
                    {
                        if (provider.TemplatePath != "normal.dotx")
                        {
                            // merge the document and extract it in new document
                            wordDoc.MailMerge.MainDocumentType = Word.WdMailMergeMainDocType.wdCatalog;
                            wordDoc.MailMerge.OpenDataSource(provider.MergeFile);
                            wordDoc.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument;
                            wordDoc.MailMerge.Execute();
                            wordDoc.Close(false, Type.Missing, Type.Missing);
                            wordDoc = word.ActiveDocument;
                        }
                        // save the new document
                        wordDoc.SaveAs2(file);
                    }
                    finally
                    {
                        wordDoc.Close(false);
                    }
                }
                finally
                {
                    word.Quit(false);
                }

    Khamis




    • Edited by Khamis Diab Wednesday, January 02, 2013 10:07 PM
    Wednesday, January 02, 2013 9:58 PM
  • Hi Khamis,

    The UI Design for Windows Store apps forum is for discussion of designing the UI of a Windows Store app. Questions about using Office components should go to the appropriate Office Development forums. Questions about implementing Windows Store apps should go to the appropriate Windows Store apps forum for the language and UI layer that you are using.

    By design, Windows Store apps are isolated from each other and cannot interact in the way you want: there is no supported way for a Windows Store app to communicate with or automate another application on the system.

    Windows Store apps cannot load arbitrary COM objects, such as the Office objects you are using in your sample code. They can load only a few specific Windows-provided objects or registration free objects installed with the application.

    It would be possible to write a component which could open, manipulate, and save a Word document, but it couldn't call an external instance of Word to do so. If the 3rd party components you mention work in Windows Store apps then this is what they must be doing.

    Any questions about whether Word provides such a component would be best asked in the Word forums, but I don't believe such a component currently exists.

    --Rob

    Thursday, January 03, 2013 1:42 AM
    Owner