0

i am create a word document using the below code

private void button1_Click(object sender, EventArgs e)
    {
        object missing = System.Reflection.Missing.Value;
        object Visible=true;
        object start1 = 0;
        object end1 = 0;

         Microsoft.Office.Interop.Word.Application WordApp;
        WordApp = new Microsoft.Office.Interop.Word.Application();
        Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
        Range rng = adoc.Range(ref start1, ref missing);

        try
        {              
            rng.Font.Name = "Hai";
            rng.InsertAfter("Hello World!");
            object filename = @"D:\MyWord.doc";
            adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
            ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            WordApp.Visible = true;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }        
    }

it is worked only when the system have MS Word.If the system doesn't contain ms word,then how can i create a word document?

leppie
  • 115,091
  • 17
  • 196
  • 297
Alphaa
  • 1
  • 3
  • [How to create excel in my c# application if msoffice is not installed](http://stackoverflow.com/questions/13120184/how-to-create-excel-in-my-c-sharp-application-if-msoffice-is-not-installed/13120402#13120402) – Hamlet Hakobyan Feb 11 '13 at 06:48

1 Answers1

2

Use Open XML SDK for Office Docs.

Mustafa Özçetin
  • 1,893
  • 1
  • 14
  • 16
Aniket Inge
  • 25,375
  • 5
  • 50
  • 78