Documentation
¶
Overview ¶
Package docx builds a minimal but complete .docx using only the Go standard library (archive/zip + encoding/xml + image).
Supported OOXML parts:
[Content_Types].xml _rels/.rels docProps/core.xml word/document.xml word/styles.xml word/settings.xml word/numbering.xml word/footnotes.xml (when footnotes are present) word/media/image*.ext (when images are present) word/_rels/document.xml.rels
Index ¶
- type Document
- func (d *Document) AddFootnote() (int, *Para)
- func (d *Document) AddParagraph(style string) *Para
- func (d *Document) AddTable() *Table
- func (d *Document) BulletNumID() int
- func (d *Document) NewOrderedNumID() int
- func (d *Document) RegisterHyperlink(url string) string
- func (d *Document) RegisterImage(path string) (string, int64, int64, error)
- func (d *Document) SaveToFile(path string) error
- func (d *Document) Write(w io.Writer) (retErr error)
- type Para
- func (p *Para) AddBoldItalicRun(text string)
- func (p *Para) AddBoldRun(text string)
- func (p *Para) AddBreak()
- func (p *Para) AddCodeColorRun(text, color string)
- func (p *Para) AddCodeRun(text string)
- func (p *Para) AddColorRun(text, color string)
- func (p *Para) AddFootnoteRef(id int)
- func (p *Para) AddFormattedRun(text string, bold, italic, strike bool)
- func (p *Para) AddHyperlinkRun(text, rId string, bold, italic, strike bool)
- func (p *Para) AddImageItem(rId, altText string, widthEMU, heightEMU int64)
- func (p *Para) AddItalicRun(text string)
- func (p *Para) AddRun(text string)
- func (p *Para) AddStrikeRun(text string)
- func (p *Para) ForceBold()
- func (p *Para) SetBlockquote()
- func (p *Para) SetBlockquoteDepth(depth int)
- func (p *Para) SetHRule()
- func (p *Para) SetNumPr(numId, ilvl int)
- type Row
- type Table
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document accumulates content and serialises it to a .docx file.
func LoadTemplate ¶
LoadTemplate opens a reference .docx and borrows its styles.xml.
func (*Document) AddFootnote ¶
AddFootnote registers a new footnote and returns its 1-based id and a *Para into which the caller writes the formatted footnote content (runs, hyperlinks, etc.).
func (*Document) AddParagraph ¶
AddParagraph appends a new paragraph with the given Word style name.
func (*Document) BulletNumID ¶
BulletNumID returns the fixed numId for unordered lists.
func (*Document) NewOrderedNumID ¶
NewOrderedNumID allocates a new numId for an ordered list instance. Each separate ordered list must get its own numId so numbering restarts.
func (*Document) RegisterHyperlink ¶
RegisterHyperlink returns a stable rId for the given URL, creating one if needed.
func (*Document) RegisterImage ¶
RegisterImage reads the image file at path, stores its bytes, and returns (rId, widthEMU, heightEMU). On error the image is skipped and ("", 0, 0, err) is returned so the caller can fall back to alt-text.
func (*Document) SaveToFile ¶
SaveToFile writes the complete .docx to path.
type Para ¶
type Para struct {
// contains filtered or unexported fields
}
Para is a paragraph under construction.
func (*Para) AddBoldItalicRun ¶
AddBoldItalicRun appends a bold+italic run.
func (*Para) AddBreak ¶
func (p *Para) AddBreak()
AddBreak adds a hard line-break to the most recent run.
func (*Para) AddCodeColorRun ¶
AddCodeColorRun appends a Courier New run with a colour (syntax highlighting).
func (*Para) AddCodeRun ¶
AddCodeRun appends a Courier New run (inline code).
func (*Para) AddColorRun ¶
AddColorRun appends a coloured run (non-monospace).
func (*Para) AddFootnoteRef ¶
AddFootnoteRef inserts an inline footnote reference mark.
func (*Para) AddFormattedRun ¶
AddFormattedRun appends a run with explicit bold/italic/strike flags. This is the general form; the typed helpers above are convenience wrappers.
func (*Para) AddHyperlinkRun ¶
AddHyperlinkRun appends a hyperlink run. bold/italic/strike carry through from the surrounding emphasis context.
func (*Para) AddImageItem ¶
AddImageItem embeds an image run.
func (*Para) AddItalicRun ¶
AddItalicRun appends an italic run.
func (*Para) AddStrikeRun ¶
AddStrikeRun appends a struck-through run.
func (*Para) ForceBold ¶
func (p *Para) ForceBold()
ForceBold makes every run in this paragraph bold regardless of run props.
func (*Para) SetBlockquote ¶
func (p *Para) SetBlockquote()
SetBlockquote adds a left border to the paragraph (depth 1).
func (*Para) SetBlockquoteDepth ¶
SetBlockquoteDepth sets the blockquote nesting depth (1-based). Each additional level adds more left indentation.