Skip to content

C# word

roy saad

Asked Jun 16, 2013, 11:53 PM EDT1 answer
Share
LinkedInX
i want to open microsoft word 2007 or 2010 

using microsoft visual studio 2010 c#

and add image and text .


i would be greatfull for your help.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi Roy,

    Follow the code below: (You need to add reference to "Microsoft.Office.Interop.Word" and "System.Reflection".
    ------------------------------------

    Missing mv = Missing.Value;
    Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
    Document myDoc = WordApp.Documents.Add(mv, mv, mv, mv);
    Paragraph paragraph = myDoc.Paragraphs.Add(mv);
    myDoc.Content.InsertParagraph();
    object start = 0;
    object end = 0;
    Microsoft.Office.Interop.Word.Range rng = myDoc.Range(ref start,ref end);
    rng.Text = "Sample Text";
    myDoc.InlineShapes.AddPicture("d:\\network.png", mv, mv, mv);
    myDoc.SaveAs("D:\\testDoc.docx", mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv, mv);
    myDoc = null;
    WordApp.Quit(mv, mv, mv);
    -------------------------------------------------

    Happy Coding :)

    Please don't forget to mark this answer if it helps:)

    Thanks.
    0