Set word document style : Word « Windows « C# / C Sharp






Set word document style

using System;

class MainClass {
    private static object n = Type.Missing;

    static void Main(string[] args) {
        Word.ApplicationClass app = new Word.ApplicationClass();
        app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;

        Word.Document doc = app.Documents.Add(ref n, ref n, ref n, ref n);

        Word.Range range = doc.Paragraphs.Add(ref n).Range;
        range.InsertBefore("Test Document");
        string style = "Heading 1";
        object objStyle = style;
        range.set_Style(ref objStyle);

        range = doc.Paragraphs.Add(ref n).Range;
        range.InsertBefore("Line one.\nLine two.");
        range.Font.Bold = 1;

        doc.PrintPreview();
        app.Visible = true;

    }
}
           
       








Related examples in the same category