Skip to content

Document

The first thing to settle is whether you are building a document from nothing or working on one that already exists, because the two barely overlap.

Creating means document.New() and a sequence of AddParagraph, AddTable and AddImage calls in the order the content should appear. Opening means document.Open(), and then the problem is finding the part you want to change, which is what the node API in Find and Edit Content is for. A third case sits between them: opening a prepared template and filling in its slots, covered in Templates and Mail Merge.

Whichever you are doing, defer doc.Close() belongs right after you get the document.

Build a document

SectionCovers
Simple ExampleThe shortest complete program. Start here.
TextRuns, paragraphs, styles, spacing, borders and lists.
Page LayoutPage size, headers and footers, page numbers.
Links and NavigationHyperlinks, bookmarks, tables of contents.
TablesRows, cells, spans and page-break behavior.
ImagesPictures, text wrapping and watermarks.
FormsThe three form control mechanisms, and which to use.

Work on an existing document

SectionCovers
Find and Edit ContentLocating, replacing, removing, splitting and merging.
Comments and RevisionsReview markup and tracked changes.
Footnotes and EndnotesNotes and their reference marks.
Templates and Mail MergeFilling a prepared document with data.
Extracting ContentReading text and properties back out.

Output

SectionCovers
Converting to PDFNative conversion and the Word-driven OLE path.
Strict ModeWriting strict OOXML rather than the transitional form.
Last updated on