GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API.

Write Word file in C# and VB.NET

Creating document content programmatically with GemBox.Document is easy and straightforward. This is done by composing document elements through constructors.

GemBox.Document supports writing Word documents in C# and VB.NET to a file or a stream. The document file format is specified through SaveOptions derived classes or a file name extension.

The following example shows how to programmatically create a new document, how to use non-Latin Unicode characters, and how to write a Word document to a file.

Screenshot
Writing Screenshot

See the full code below, use Run Example to execute.

using System;
using System.Linq;
using System.Text;
using GemBox.Document;
using GemBox.Document.Tables;
using System.Text.RegularExpressions;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = new DocumentModel();

        document.Sections.Add(
            new Section(document,
                new Paragraph(document,
                    new Run(document, "English: Hello"),
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Russian: "),
                    new Run(document, new string(new char[] { '\u0417', '\u0434', '\u0440', '\u0430', '\u0432', '\u0441', '\u0442', '\u0432', '\u0443', '\u0439', '\u0442', '\u0435' })),
                    new SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    new Run(document, "Chinese: "),
                    new Run(document, new string(new char[] { '\u4f60', '\u597d' }))),
                new Paragraph(document, "In order to see Russian and Chinese characters you need to have appropriate fonts on your machine.")));

        document.Save("Writing.docx");
    }
}
Imports System
Imports System.Linq
Imports System.Text
Imports GemBox.Document
Imports GemBox.Document.Tables
Imports System.Text.RegularExpressions

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = New DocumentModel

        document.Sections.Add(
            New Section(document,
                New Paragraph(document,
                    New Run(document, "English: Hello"),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Russian: "),
                    New Run(document, New String(New Char() {ChrW(&H417), ChrW(&H434), ChrW(&H440), ChrW(&H430), ChrW(&H432), ChrW(&H441), ChrW(&H442), ChrW(&H432), ChrW(&H443), ChrW(&H439), ChrW(&H442), ChrW(&H435)})),
                    New SpecialCharacter(document, SpecialCharacterType.LineBreak),
                    New Run(document, "Chinese: "),
                    New Run(document, New String(New Char() {ChrW(&H4F60), ChrW(&H597D)}))),
                New Paragraph(document, "In order to see Russian and Chinese characters you need to have appropriate fonts on your machine.")))

        document.Save("Writing.docx")

    End Sub

End Module

Check next sample.