API
Positional arguments are only considered part of the API where they are explicitly mentioned in the docstrings. Otherwise, the API is built on keyword arguments so that missing options and properties can be added in the future without breaking existing code.
Types
WriteDocx.AtLeast — Type
AtLeast(length)A minimum Length, for properties where Word may grow a measure past the given value to fit its content, such as the line of a Spacing.
WriteDocx.AutomaticDefault — Type
AutomaticDefault{T}Signals that either a value of type T is accepted or automatic, for which the viewer application chooses appropriate behavior.
WriteDocx.Body — Type
Body(sections::Vector{Section})The document body which contains the sections of the document.
WriteDocx.Bookmark — Type
Bookmark(name::String, children::AbstractVector = [])Marks its children with a bookmark called name, which a Hyperlink or PageReference can point at. A bookmark without children marks a position in the document rather than a range of content.
Bookmarks can hold run elements, in which case they belong into a Paragraph, or block elements, in which case they go wherever a Paragraph can go. Names must be unique within a document, contain no whitespace and be at most 40 characters long, because Word silently truncates longer names and replaces whitespace with underscores, which would break every link pointing at them.
WriteDocx.Column — Type
Column(; [width, space])Describes a single column. width sets the column width, and space sets the whitespace after the column (before the next column).
See also: Columns
WriteDocx.Columns — Type
Columns(; kwargs...)Sets the columns for a Section.
Keyword arguments
| Keyword | Description |
|---|---|
equal::Bool = true | Sets all columns to be equal-width with space between every column |
num::Int | The number of columns to layout. Ignored if equal==false. |
space::Twip | The space between columns. Ignored if equal==false. |
sep::Bool = false | Sets whether a vertical separator line is drawn between columns |
cols::Vector{Column} | A vector of custom columns. May not be specified with equal==true. |
WriteDocx.ComplexField — Type
ComplexField(instruction::String; dirty = true)Creates a complex field with a specific instruction that has an effect in the viewer application. If dirty === true, the field will be reevaluated when opening the docx file.
The ComplexField element must be paired with a following ComplexFieldEnd. For some purposes, other elements may appear between the two.
WriteDocx.ComplexFieldEnd — Type
ComplexFieldEnd()Every ComplexField element must be paired with this element.
WriteDocx.DocDefaults — Type
DocDefaults(; kwargs...)Holds the default run and paragraph properties for a Document. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
run::RunProperties | The default properties for every Run. |
paragraph::ParagraphProperties | The default properties for every Paragraph. |
WriteDocx.Document — Method
Document(body::Body; styles::Styles = Styles([]))The root object containing all other elements that make up the document.
WriteDocx.Fonts — Type
Fonts(; [ascii::String, high_ansi::String, complex::String, east_asia::String])
Fonts(font; kwargs...)Specifies fonts to use for four different Unicode character ranges. The convenience constructor with one positional argument changes the font for ascii and high_ansi, which should usually be the same.
WriteDocx.Footer — Type
Footer(children::AbstractVector)Contains elements for use in a Section's footer section. Each element should satisfy is_block_element.
WriteDocx.Footers — Type
Footers(; default::Footer, [first::Footer, even::Footer])Holds information about the Footers of a Section. A default Footer must always be specified. If first is set, the first page of the section gets this separate footer. If even is set, every even-numbered page of the section gets this separate footer, making default effectively mean odd.
WriteDocx.Header — Type
Header(children::AbstractVector)Contains elements for use in a Section's header section. Each element should satisfy is_block_element.
WriteDocx.Headers — Type
Headers(; default::Header, [first::Header, even::Header])Holds information about the Headers of a Section. A default Header must always be specified. If first is set, the first page of the section gets this separate header. If even is set, every even-numbered page of the section gets this separate header, making default effectively mean odd.
WriteDocx.HexColor — Type
HexColor(s::String)A color in hexadecimal RGB format, for example "FF0000" for red or "333333" for a dark gray.
WriteDocx.Hyperlink — Type
Hyperlink(children::AbstractVector; anchor::String)Turns its children into a link that jumps to the Bookmark called anchor, which must exist somewhere in the document.
The link is not styled differently from the surrounding text unless a style says so, because Word's blue underlined look comes from its built-in Hyperlink character style, which this package does not add to a document.
WriteDocx.Image — Type
Image(m::MIME, object)Represents an image of MIME type m that can be written to an appropriate file when writing out a docx document. The object needs to have a show method for m defined for the default behavior to work.
WriteDocx.Image — Method
Image(path::String)Create an Image pointing to the file at path. The MIME type is determined by file extension.
WriteDocx.InlineDrawing — Type
InlineDrawing{T}(; image::T, width::EMU, height::EMU)Create an InlineDrawing object which, as the name implies, can be placed inline with text inside Runs.
WriteDocx supports different types T for the image argument. If T is a String, image is treated as the file path to an existing .png or .svg image. You can pass an Image object which can hold a reference to an object that can be written to a file with the desired MIME type at render time. You can also use SVGWithPNGFallback to place .svg images with better fallback behavior.
Width and height of the placed image are set via width and height, note that you have to determine these values yourself for any image you place, a correct aspect ratio will not be determined automatically.
WriteDocx.LineSpacing — Type
LineSpacing(value)The height of the lines in a paragraph, which is one of:
- a
Percentof single spacing, so150percentis one-and-a-half spacing - a
Length, for lines of exactly that height, such as14pt - an
AtLeast, for a height that may grow to fit tall content
The bare value can be passed as the line of a Spacing as well, so line = 150percent and line = LineSpacing(150percent) are equivalent.
WriteDocx.PageMargins — Type
PageMargins(; top, right, bottom, left, kwargs...)Describes page margins in a Section.
Keyword arguments
| Keyword | Description |
|---|---|
top::Twip | The top margin. |
right::Twip | The right margin. |
bottom::Twip | The bottom margin. |
left::Twip | The left margin. |
header::Twip=Twip(0) | The header margin. |
footer::Twip=Twip(0) | The footer margin. |
gutter::Twip=Twip(0) | The gutter margin. |
WriteDocx.PageReference — Type
PageReference(anchor::String)Shows the number of the page that the Bookmark called anchor is on, and links to it. Word computes the number when it recalculates the document's fields, so it is correct in print and export but may show as empty until then.
WriteDocx.PageSize — Method
PageSize(width, height)The size of a page. If width > height, the page is set to PageOrientation.landscape.
WriteDocx.Paragraph — Type
Paragraph(children::Vector{Any}, properties::ParagraphProperties)
Paragraph(children::AbstractVector; kwargs...)A paragraph can contain children that satisfy is_run_element. The second convenience constructor forwards all keyword arguments to ParagraphProperties.
WriteDocx.ParagraphBorder — Type
ParagraphBorder(; kwargs...)Holds properties for one border of a table cell and is used by ParagraphBorders. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
color::AutomaticDefault{[HexColor]@ref} | The color of the border. |
shadow::Bool | Applies a shadow effect if true. |
space::Point | The spacing between border and content. |
size::EighthPoint | The thickness of the border line. |
style::BorderStyle.T | The line style of the border. |
WriteDocx.ParagraphBorders — Type
ParagraphBorders(; kwargs...)Holds properties for the borders of a Paragraph and is used by ParagraphProperties. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
top::ParagraphBorder | The properties of the top border. |
bottom::ParagraphBorder | The properties of the bottom border. |
left::ParagraphBorder | The properties of the left border. |
right::ParagraphBorder | The properties of the right border. |
between::ParagraphBorder | The properties of horizontal border that lies between adjacent paragraphs. |
WriteDocx.ParagraphProperties — Type
ParagraphProperties(; kwargs...)Holds properties for a Paragraph. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
style::String | The name of the style applied to this Paragraph. |
justification::Justification.T | The justification of the paragraph. |
tabs::Vector{TabStop} | The tab stops that a Tab in this paragraph advances to. |
WriteDocx.Percent — Type
Percent(value::Float64)A relative measure for the properties where Word takes a proportion of some other quantity instead of an absolute Length, such as the width of a TableProperties or the line of a Spacing. For convenience, the constant percent is provided for Percent(1).
WriteDocx.Run — Type
Run(children::AbstractVector, properties::RunProperties)
Run(children::AbstractVector; kwargs...)Create a Run with children who all have to satisfy is_inline_element.
The second convenience constructor forwards all keyword arguments to the RunProperties constructor.
WriteDocx.RunProperties — Type
RunProperties(; kwargs...)Holds properties for a Run. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
style::String | The name of the style applied to this Run. |
color::AutomaticDefault{HexColor} | The color of the text. |
size::HalfPoint | The font size. |
valign::VerticalAlignment.T | Whether text is shown with baseline, superscript or subscript style. |
fonts::Fonts | The font settings for this text. |
bold::Bool | Whether text should be bold. Note that this works like a toggle when nested, turning boldness off again the second time it's true. |
italic::Bool | Whether text should be italic. Note that this works like a toggle when nested, turning italic style off again the second time it's true. |
strike::Bool | Whether text should be struck through. Note that this works like a toggle when nested, turning strikethrough off again the second time it's true. |
underline::Underline | How the text should be underlined. |
WriteDocx.SVGWithPNGFallback — Type
SVGWithPNGFallback(; svg, png)Create a SVGWithPNGFallback for the svg svg and the fallback png. If svg or png are AbstractStrings, they will be treated as paths to image files. Otherwise, they should be Images with the appropriate MIME types. Use SVGImage and PNGImage as shortcuts to create these.
Word Online and other services like Slack preview don't work when a simple svg file is added via InlineDrawing{String}. SVGWithPNGFallback supplies a fallback png file which will be used for display in those situations. Note that it is your responsibility to check whether the png file is an accurate replacement for the svg.
WriteDocx.Section — Type
Section(children::AbstractVector, properties::SectionProperties)
Section(children::AbstractVector; kwargs...)A section of a document contains a vector of children which should satisfy is_block_element. The docx format does not have a concept of individual pages, although Section might be thought of as a group of related "page"s.
The content within a document's Sections is laid out into actual pages dynamically in the viewer application. A Section has SectionProperties which then control how those pages are rendered.
The second convenience constructor forwards all keyword arguments to the SectionProperties constructor.
WriteDocx.SectionProperties — Type
SectionProperties(; kwargs...)Holds properties for a Section.
Keyword arguments
| Keyword | Description |
|---|---|
pagesize::PageSize | The size of each page in the section. |
margins::PageMargins | The margins for each page in the section |
valign::PageVerticalAlign.T | The vertical alignment of content on each page of the section. |
headers::Headers | Defines the header content shown at the top of each page of the section. |
footers::Footers | Defines the footer content shown at the bottom of each page of the section. |
columns::Columns | Configures the columns in the section |
WriteDocx.Shading — Type
Shading(; pattern = ShadingPattern.clear, fill = automatic, color = automatic)Specifies the background shading of an element, where fill is the background color, color the foreground color of the pattern drawn on top of it.
WriteDocx.Spacing — Type
Spacing(; before = nothing, after = nothing, line = nothing)Holds the spacing properties of a Paragraph, where before and after are the space above and below it and line is its LineSpacing.
WriteDocx.Styles — Type
Styles(styles::Vector{Style}, doc_defaults::DocDefaults)
Styles(styles; kwargs...)Holds style information for a Document. The second convenience constructor forwards all keyword arguments to DocDefaults.
WriteDocx.Tab — Type
WriteDocx.TabStop — Type
TabStop(position::Length; alignment = TabAlignment.start, leader = TabLeader.none)A tab stop of a ParagraphProperties, where position is measured from the left margin. A Tab in the paragraph's text advances to the next stop, filling the jumped space with the leader character.
WriteDocx.Table — Type
Table(rows::Vector{TableRow}, properties::TableProperties; grid = Twip[])
Table(rows; grid = Twip[], kwargs...)A table which can hold a vector of TableRows. The grid holds the widths of the table's columns, which Word lays the cells out at if properties.layout is TableLayout.fixed, so grid = [4cm, 2cm] describes a two-column table. The second convenience constructor forwards all remaining keyword arguments to TableProperties.
WriteDocx.TableCell — Type
TableCell(children::Vector{Any}, properties::TableCellProperties)
TableCell(children::AbstractVector; kwargs...)One cell of a Table which can hold elements that satisfy is_block_element. The second convenience constructor forwards all keyword arguments to TableCellProperties.
WriteDocx.TableCellBorder — Type
TableCellBorder(; kwargs...)Holds properties for one border of a table cell and is used by TableCellBorders. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
color::AutomaticDefault{[HexColor]@ref} | The color of the border. |
shadow::Bool | Applies a shadow effect if true. |
space::Point | The spacing between border and content. |
size::EighthPoint | The thickness of the border line. |
style::BorderStyle.T | The line style of the border. |
WriteDocx.TableCellBorders — Type
TableCellBorders(; kwargs...)Holds properties for the borders of a TableCell and is used by TableCellProperties. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
top::TableCellBorder | The properties of the top border. |
bottom::TableCellBorder | The properties of the bottom border. |
start::TableCellBorder | The properties of the left border in left-to-right text. |
stop::TableCellBorder | The properties of the right border in left-to-right text. |
inside_h::TableCellBorder | The properties of the horizontal border that lies between adjacent cells. |
inside_v::TableCellBorder | The properties of the vertical border that lies between adjacent cells. |
tl2br::TableCellBorder | The properties of the diagonal border going from the top left to the bottom right corner. |
tr2bl::TableCellBorder | The properties of the diagonal border going from the top right to the bottom left corner. |
WriteDocx.TableCellMargins — Type
TableCellMargins(; kwargs...)Holds properties for the margins of a TableCell and is used by TableCellProperties. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
top::Twip | The top margin. |
bottom::Twip | The bottom margin. |
start::Twip | The left margin in left-to-right text. |
stop::Twip | The right margin in left-to-right text. |
WriteDocx.TableCellProperties — Type
TableCellProperties(; kwargs...)Holds properties for a TableCell. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
width::TableWidth | The width of the cell, for example 50percent of the table's width. |
borders::TableCellBorders | The border style of the cell. |
vertical_merge::Bool | Should be set to true if this cell should be merged with the one above it. |
gridspan::Int | The number of cells this cell should span in horizontal direction. |
margins::TableCellMargins | The margins of the cell. |
valign::VerticalAlign.T | The vertical alignment of the content in the cell. |
hide_mark::Bool | If true, hides the editor mark so that the table cell can fully collapse if it's empty. |
shading::Shading | The shading (background fill and pattern) of the cell. |
WriteDocx.TableLevelCellMargins — Type
TableCellMargins(; kwargs...)Holds properties for the default margins of all TableCells in a Table and is used by TableProperties. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
top::Twip | The top margin. |
bottom::Twip | The bottom margin. |
start::Twip | The left margin in left-to-right text. |
stop::Twip | The right margin in left-to-right text. |
WriteDocx.TableProperties — Type
TableProperties(; kwargs...)Holds properties for a Table. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
width::TableWidth | The width of the table, for example 100percent to fill the text column. |
layout::TableLayout.T | The algorithm with which Word lays the columns out. |
margins::TableLevelCellMargins | Margins for all cells in the table. |
spacing::Twip | The space between adjacent cells and the edges of the table. |
justification::Justification.T | The justification of the table. |
WriteDocx.TableRow — Type
TableRow(cells::Vector{TableCell}, properties::TableRowProperties)
TableRow(cells; kwargs...)One row of a Table which can hold a vector of TableCells. The second convenience constructor forwards all keyword arguments to TableRowProperties.
WriteDocx.TableRowProperties — Type
TableRowProperties(; kwargs...)Holds properties for a TableRow. All properties are optional.
Keyword arguments
| Keyword | Description |
|---|---|
header::Bool | Whether this row should be part of the header section which is repeated after every page break. |
height::TableRowHeight | The height of the table row. |
WriteDocx.TableWidth — Type
TableWidth(value)The width of a Table or a TableCell, which is one of:
- a
Percentof the surrounding text column for a table, or of the table for a cell, so100percentmakes a table fill the column - a
Length, for an absolute width such as12cm automatic, which sizes the table or cell to fit its content
The bare value can be passed as a width as well, so width = 100percent and width = TableWidth(100percent) are equivalent.
WriteDocx.Underline — Type
Underline(; color = automatic, pattern = UnderlinePattern.single)Specifies how text is underlined. Use pattern = UnderlinePattern.none to switch off an underline inherited from a style.
Lengths
WriteDocx.Centimeter — Type
Centimeter(value::Float64) <: LengthA length of one centimeter, or 1/2.54 of an inch. For convenience, the constants cm and mm are provided for Centimeter(1) and Centimeter(0.1), respectively.
WriteDocx.EMU — Type
EMU(value::Float64) <: LengthA length of one English metric unit, or 1/914400 of an inch. For convenience, the constant emu is provided for EMU(1).
WriteDocx.EighthPoint — Type
EighthPoint(value::Float64) <: LengthA length of one eight of a typographic point, or 1/576 of an inch. For convenience, the constant eighthpt is provided for EighthPoint(1).
WriteDocx.HalfPoint — Type
HalfPoint(value::Float64) <: LengthA length of a half typographic point, or 1/144 of an inch. For convenience, the constant halfpt is provided for HalfPoint(1).
WriteDocx.Inch — Type
Inch(value::Float64) <: LengthA length of one inch. For convenience, the constant inch is provided for Inch(1).
WriteDocx.Length — Type
LengthThe supertype for all length metrics that WriteDocx can handle. Each Length can be converted to any other Length and can therefore be passed to any struct that stores a specific length type.
WriteDocx.Point — Type
Point(value::Float64) <: LengthA length of one typographic point, or 1/72 of an inch. For convenience, the constant pt is provided for Point(1).
WriteDocx.Twip — Type
Twip(value::Float64) <: LengthA length of one twip, or twentieth of a point, or 1/1440 of an inch. For convenience, the constant twip is provided for Twip(1).
Enums
WriteDocx.BorderStyle — Module
BorderStyleAn enum that can be either single, dash_dot_stroked, dashed, dash_small_gap, dot_dash, dot_dot_dash, dotted, double, double_wave, inset, nil, none, outset, thick, thick_thin_large_gap, thick_thin_medium_gap, thick_thin_small_gap, thin_thick_large_gap, thin_thick_medium_gap, thin_thick_small_gap, thin_thick_thin_large_gap, thin_thick_thin_medium_gap, thin_thick_thin_small_gap, three_d_emboss, three_d_engrave, triple or wave
WriteDocx.Justification — Module
JustificationAn enum that can be either start, stop, center, both or distribute.
WriteDocx.UnderlinePattern — Module
UnderlinePatternAn enum that can be either dash, dash_dot_dot_heavy, dash_dot_heavy, dashed_heavy, dash_long, dash_long_heavy, dot_dash, dot_dot_dash, dotted, dotted_heavy, double, none, single, thick, wave, wavy_double, wavy_heavy or words.
WriteDocx.ShadingPattern — Module
ShadingPattern
An enum that can be either clear, diag_cross, diag_stripe, horz_cross, horz_stripe, nil, thin_diag_cross, or solid.
WriteDocx.VerticalAlign — Module
VerticalAlignAn enum that can be bottom, center or top.
WriteDocx.VerticalAlignment — Module
VerticalAlignmentAn enum that can be either baseline, subscript or superscript.
WriteDocx.TableLayout — Module
TableLayoutAn enum that can be either autofit or fixed. With fixed, Word lays the columns out at the widths given by the table's grid, with autofit it sizes them to their content.
WriteDocx.TabAlignment — Module
TabAlignmentAn enum that can be either start, stop, center, decimal, bar or clear, where clear removes a tab stop that the paragraph's style defines.
WriteDocx.TabLeader — Module
TabLeaderAn enum that can be either none, dot, hyphen, underscore, heavy or middle_dot, the character with which Word fills the space a tab jumps.