none
Generate things from scratch RRS feed

  • Question

  • Hello all! im new to this and i would like a simple Hello World example...

    like... to create the most basic presentation u do like this, and to add a new slide u do this, and to add a text box u do this, and to change the text of the textbox to Hello World u do this... i dont know if im asking too much... google does is not helping much now... and the MS samples are way to complex... wich i think is very odd, because u usually find alot more hello world and simple daily tasks then the "Merge Presentations"...

    tks anyway!

    Wednesday, December 28, 2011 10:35 PM

Answers

  • Hi LeonardoIndex,

     

    Thanks for post in the MSDN Forum.

     

    This is a sample. I hope it can help you.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using DocumentFormat.OpenXml.Packaging;
    using DocumentFormat.OpenXml.Wordprocessing;
    using DocumentFormat.OpenXml;
     
    namespace WindowsFormsApplication10
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                SaveFileDialog objSaveFileDialog = new SaveFileDialog();
                objSaveFileDialog.Filter = "Word Document (*.docx)|*docx";
                objSaveFileDialog.ShowDialog();
                string strPath = objSaveFileDialog.FileName;
                using (WordprocessingDocument objWordDocument = 
                    WordprocessingDocument.Create(strPath,
                    WordprocessingDocumentType.Document))
                {
                    MainDocumentPart objMainDocumentPart = 
                        objWordDocument.AddMainDocumentPart();
                    Document objDocument = new Document();
                    Body objBody = new Body();
                    Paragraph objParagraph = new Paragraph();
                    Run objRun = new Run();
                    Text objText = new Text();
                    objText.Text = "Hello World!";
                    objRun.Append(objText);
                    objParagraph.Append(objRun);
                    objBody.Append(objParagraph);
                    objDocument.Append(objBody);
                    objMainDocumentPart.Document = objDocument;
                    DocumentSettingsPart objDocumentSettingPart = 
                        objMainDocumentPart.AddNewPart<DocumentSettingsPart>();
                    objDocumentSettingPart.Settings = new Settings();
                    Compatibility objCompatibility = new Compatibility();
                    CompatibilitySetting objCompatibilitySetting = 
                        new CompatibilitySetting() 
                        { 
                            Name = CompatSettingNameValues.CompatibilityMode, 
                            Uri = "http://schemas.microsoft.com/office/word", 
                            Val = "14" 
                        };
                    objCompatibility.Append(objCompatibilitySetting);
                    objDocumentSettingPart.Settings.Append(objCompatibility);
                }  
            }
        }
    }

     

    Have a good day,

     

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 30, 2011 7:47 AM
    Moderator