Automation in creating or open word document RRS feed

  • Question

  • Hi everyone!

    I nedd help in using automation in my siverlight project.

    I've succeed in creating a new document from the web project of my solution:

    I create a document, write "MY WONDERFUL TEXT" and save it in My Documents with MyDocument.doc name.

    this is the code:

            Type WordType = Type.GetTypeFromProgID("Word.Application");
            object objApplication;
            object objDocuments;
            object objDocument;
            objApplication = System.Activator.CreateInstance(Type.GetTypeFromProgID("Word.Application"));
            objApplication.GetType().InvokeMember("Visible", BindingFlags.SetProperty, null, objApplication, new Object[] { true });
            objDocuments = objApplication.GetType().InvokeMember("Documents", BindingFlags.Default | BindingFlags.GetProperty, null, objApplication, null);
            objDocument = objDocuments.GetType().InvokeMember("Add", BindingFlags.Default | BindingFlags.InvokeMethod, null, objDocuments, null);
            Object WordSelection = objApplication.GetType().InvokeMember("Selection", BindingFlags.GetProperty, null, objApplication, null);
            WordSelection.GetType().InvokeMember("TypeText", BindingFlags.InvokeMethod, null, WordSelection, new object[] { "MY WONDERFUL TEXT" });
           objDocument.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, objDocument, new object[] { "MyDocument.doc" });
    My problem is that i would like to insert images, tables or others elements:
    there are two way:
    1) create a document whit my template, my images before, and then open it by code and write text (but i don't know how)
    2) insert by code also images, tables and others (but i don't know how)
    The reason to do this is because i've to report some database data in a word document. If you have other way to do this it wouls be greate!
    thanks in advance!
    Friday, April 13, 2012 6:41 AM