Create Hello World using WordProcessingML. Return to Home Page
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace OpenXml
{
    class Program
    {
        static void Main(string[] args)
        {

            using (WordprocessingDocument document =
                   WordprocessingDocument.Create(@"C:\Word\HelloWorld.docx",
                                 WordprocessingDocumentType.Document))
            {
                MainDocumentPart mainPart = document.AddMainDocumentPart();
                mainPart.Document = new Document();
                Body body = new Body();
                Paragraph paragraph = new Paragraph();
                Run run_paragraph = new Run();
                Text text_paragraph = new Text("Hello World!");
                run_paragraph.Append(text_paragraph);
                paragraph.Append(run_paragraph);
                body.Append(paragraph);
                mainPart.Document.Append(body);
                mainPart.Document.Save();
            }
        }
    }
}

Last edited Feb 7, 2014 at 3:07 AM by Tatibah, version 4