element

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: LGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RubyAlignCenter           = "center"
	RubyAlignDistributeLetter = "distributeLetter"
	RubyAlignDistributeSpace  = "distributeSpace"
	RubyAlignLeft             = "left"
	RubyAlignRight            = "right"
	RubyAlignRightVertical    = "rightVertical"
)

Ruby alignment values (PHPWord ComplexType\RubyProperties).

View Source
const (
	EdGrpNone           = "none"
	EdGrpEveryone       = "everyone"
	EdGrpAdministrators = "administrators"
	EdGrpContributors   = "contributors"
	EdGrpEditors        = "editors"
	EdGrpOwners         = "owners"
	EdGrpCurrent        = "current"
)

ST_EdGrp values used on w:permStart.

View Source
const (
	SDTTypePlainText = "plainText"
	SDTTypeComboBox  = "comboBox"
	SDTTypeDropDown  = "dropDownList"
	SDTTypeDate      = "date"
	SDTTypeCheckbox  = "checkbox"
	SDTTypeRichText  = "richText"
)

SDT control types (CT_SdtPr choice). PHPWord uses plainText|comboBox|dropDownList|date.

View Source
const (
	SDTCheckboxUnchecked = "\u2610" // ☐
	SDTCheckboxChecked   = "\u2612" // ☒

)

Checkbox glyphs used in w:sdtContent (Word 2010 w14:checkbox).

View Source
const (
	HeaderAuto  = "default"
	HeaderFirst = "first"
	HeaderEven  = "even"
)

Header types (PHPWord Element\Header).

Variables

This section is empty.

Functions

func CheckboxFont added in v0.9.0

func CheckboxFont() string

CheckboxFont is the East-Asian font Word expects for w14:checkbox glyphs.

func NormalizeSDTType added in v0.9.0

func NormalizeSDTType(typ string) string

NormalizeSDTType maps PHPWord / shorthand type names onto the OpenXML control kind.

func ParseAllowEdit added in v0.9.0

func ParseAllowEdit(groupOrUser string) (edGrp, ed string)

ParseAllowEdit maps a user-facing group or user name onto w:edGrp / w:ed.

Types

type Base

type Base struct {
	RelationID   int
	ElementID    string
	DocPart      string
	SectionID    int
	TrackChange  *TrackChange
	CommentStart *Comment
	CommentEnd   *Comment
	EditGroup    string // w:permStart w:edGrp (everyone, editors, …)
	EditUser     string // w:permStart w:ed
	// contains filtered or unexported fields
}

Base is embedded by every concrete element.

func (*Base) GetCommentRangeEnd

func (b *Base) GetCommentRangeEnd() *Comment

func (*Base) GetCommentRangeStart

func (b *Base) GetCommentRangeStart() *Comment

func (*Base) GetTrackChange

func (b *Base) GetTrackChange() *TrackChange

func (*Base) HasAllowEdit added in v0.9.0

func (b *Base) HasAllowEdit() bool

HasAllowEdit reports whether a permission range should be written.

func (*Base) Parent

func (b *Base) Parent() Element

func (*Base) SetChangeInfo

func (b *Base) SetChangeInfo(typ, author, date string)

func (*Base) SetCommentRangeEnd

func (b *Base) SetCommentRangeEnd(c *Comment)

func (*Base) SetCommentRangeStart

func (b *Base) SetCommentRangeStart(c *Comment)

func (*Base) SetTrackChange

func (b *Base) SetTrackChange(tc *TrackChange)

type Bookmark

type Bookmark struct {
	Base
	Name string
}

Bookmark is a bookmark start/end pair.

func (*Bookmark) Type

func (b *Bookmark) Type() string

type Cell

type Cell struct {
	Container
	Style style.Cell
	Width int
}

Cell is a table cell and a container.

func NewCell

func NewCell(width int, st ...any) *Cell

NewCell constructs a cell.

func (*Cell) AllowEdit added in v0.9.0

func (c *Cell) AllowEdit(groupOrUser string) *Cell

AllowEdit marks this cell's contents as an exception range in a protected document.

func (*Cell) SetBorder added in v0.6.0

func (c *Cell) SetBorder(side, borderStyle string, size int, color string)

SetBorder sets one cell border (side: top, left, bottom, right, or all).

func (*Cell) SetPadding added in v0.6.0

func (c *Cell) SetPadding(top, left, bottom, right int)

SetPadding sets cell inner margins in twips (w:tcMar).

func (*Cell) SetTextDirection added in v0.6.0

func (c *Cell) SetTextDirection(v string) *Cell

SetTextDirection sets w:textDirection (lrTb, tbRl, btLr, …) and returns the cell.

func (*Cell) SetVAlign added in v0.9.0

func (c *Cell) SetVAlign(v string) *Cell

SetVAlign sets w:vAlign (top, center, bottom) and returns the cell.

func (*Cell) SetVerticalAlignment added in v0.6.0

func (c *Cell) SetVerticalAlignment(v string)

SetVerticalAlignment sets w:vAlign (top, center, bottom).

func (*Cell) Type

func (c *Cell) Type() string

type Chart

type Chart struct {
	Base
	ChartType  string
	Categories []string
	Values     []float64
	Style      style.Chart
	SeriesName string
	Series     []ChartSeries
}

Chart is a chart drawing.

func (*Chart) AddComboSeries added in v0.7.0

func (c *Chart) AddComboSeries(kind string, categories []string, values []float64, name string, secondary bool)

AddComboSeries appends a series with an explicit chart kind and axis.

func (*Chart) AddSeries

func (c *Chart) AddSeries(categories []string, values []float64, name ...string)

AddSeries appends a data series (PHPWord Chart::addSeries).

func (*Chart) SetDataLabels added in v0.7.0

func (c *Chart) SetDataLabels(opts style.DataLabelOptions)

SetDataLabels configures c:dLbls visibility and dLblPos.

func (*Chart) SetLegendPosition added in v0.7.0

func (c *Chart) SetLegendPosition(pos string)

SetLegendPosition shows the legend at pos (t/b/l/r).

func (*Chart) SetLineMarker added in v0.7.0

func (c *Chart) SetLineMarker(symbol string)

SetLineMarker sets the c:marker symbol for line series (circle, diamond, none, …).

func (*Chart) SetLineSmooth added in v0.7.0

func (c *Chart) SetLineSmooth(on bool)

SetLineSmooth enables c:smooth on line series.

func (*Chart) SetMajorGridlines added in v0.7.0

func (c *Chart) SetMajorGridlines(visible bool)

SetMajorGridlines toggles major gridlines on both axes.

func (*Chart) Type

func (c *Chart) Type() string

type ChartSeries

type ChartSeries struct {
	Categories    []string
	Values        []float64
	Name          string
	Kind          string
	SecondaryAxis bool
	Smooth        bool
	Marker        string
}

ChartSeries is one data series on a chart.

type CheckBox

type CheckBox struct {
	Text
	Name    string
	Checked bool
}

CheckBox is a checkbox form field.

func NewCheckBox

func NewCheckBox(name, text string, font, para any) *CheckBox

func (*CheckBox) Type

func (c *CheckBox) Type() string

type Comment

type Comment struct {
	Container
	Author       string
	Initials     string
	Date         string
	CommentID    int
	StartElement Element
	EndElement   Element
}

Comment is a comment range.

func (*Comment) Type

func (c *Comment) Type() string

type Container

type Container struct {
	Base
	Kind string
	// contains filtered or unexported fields
}

Container is a parent that holds child elements (section, cell, textrun, ...).

func (*Container) AddBookmark

func (c *Container) AddBookmark(name string) *Bookmark

AddBookmark appends a bookmark.

func (*Container) AddChart

func (c *Container) AddChart(typ string, categories []string, values []float64, s ...style.Chart) *Chart

AddChart appends a simple chart.

func (*Container) AddCheckBox

func (c *Container) AddCheckBox(name, text string, styles ...any) *CheckBox

AddCheckBox appends a checkbox form field.

func (*Container) AddComment

func (c *Container) AddComment(author, initials, date string) *Comment

AddComment appends a comment range container.

func (*Container) AddDMLShape added in v0.8.0

func (c *Container) AddDMLShape(prst string, width, height int, fill, line string, lineWidth int) *DMLShape

AddDMLShape appends a DrawingML preset shape, optionally with textbox content.

func (*Container) AddDeletion added in v0.4.0

func (c *Container) AddDeletion(text, author, date string, styles ...any) *Text

AddDeletion appends text marked as a tracked deletion (w:del).

func (*Container) AddEndnote

func (c *Container) AddEndnote(styles ...any) *Endnote

AddEndnote appends an endnote.

func (*Container) AddField

func (c *Container) AddField(typ string, properties map[string]string, options []string, text string) *Field

AddField appends a Word field.

func (*Container) AddFootnote

func (c *Container) AddFootnote(styles ...any) *Footnote

AddFootnote appends a footnote.

func (*Container) AddFormField

func (c *Container) AddFormField(typ string, styles ...any) *FormField

AddFormField appends a form field of the given type.

func (*Container) AddFormula

func (c *Container) AddFormula(m *math.Math) *Formula

AddFormula appends an OMML formula.

func (*Container) AddImage

func (c *Container) AddImage(source string, styles ...any) *Image

AddImage appends an image from a filesystem path.

func (*Container) AddImageBytes

func (c *Container) AddImageBytes(name string, data []byte, styles ...any) *Image

AddImageBytes appends an image from memory.

func (*Container) AddInsertion added in v0.4.0

func (c *Container) AddInsertion(text, author, date string, styles ...any) *Text

AddInsertion appends text marked as a tracked insertion (w:ins).

func (*Container) AddLine

func (c *Container) AddLine(s ...style.Line) *Line

AddLine appends a VML line shape.

func (c *Container) AddLink(target, text string, styles ...any) *Link

AddLink appends a hyperlink.

func (*Container) AddListItem

func (c *Container) AddListItem(text string, depth int, styles ...any) *ListItem

AddListItem appends a numbered or bulleted paragraph.

func (*Container) AddListItemRun

func (c *Container) AddListItemRun(depth int, listStyle any, para any) *ListItemRun

AddListItemRun appends a rich list paragraph.

func (*Container) AddMath added in v0.8.0

func (c *Container) AddMath(formula string) *Formula

AddMath parses a basic LaTeX expression into a native OMML formula.

func (*Container) AddNumPages added in v0.5.0

func (c *Container) AddNumPages() *Field

AddNumPages inserts a NUMPAGES field.

func (*Container) AddOLEObject

func (c *Container) AddOLEObject(source string, styles ...any) *OLEObject

AddOLEObject appends an embedded OLE object.

func (*Container) AddObject

func (c *Container) AddObject(source string, styles ...any) *OLEObject

AddObject is the deprecated PHPWord alias for AddOLEObject.

func (*Container) AddPageBreak

func (c *Container) AddPageBreak() *PageBreak

AddPageBreak inserts a page break.

func (*Container) AddPageNumber added in v0.5.0

func (c *Container) AddPageNumber() *Field

AddPageNumber inserts a PAGE field.

func (*Container) AddPreserveText

func (c *Container) AddPreserveText(text string, styles ...any) *PreserveText

AddPreserveText appends a mail-merge / header field run.

func (*Container) AddRuby

func (c *Container) AddRuby(base, ruby *TextRun, props RubyProperties) *Ruby

AddRuby appends phonetic guide text.

func (*Container) AddSDT

func (c *Container) AddSDT(typ string) *SDT

AddSDT appends a structured document tag (PHPWord addSDT).

func (*Container) AddSDTCheckbox added in v0.9.0

func (c *Container) AddSDTCheckbox(alias, tag string, checked bool) *SDT

AddSDTCheckbox appends a Word 2010 checkbox (w14:checkbox).

func (*Container) AddSDTDate added in v0.9.0

func (c *Container) AddSDTDate(alias, tag, dateFormat string) *SDT

AddSDTDate appends a date picker (w:date). dateFormat is w:dateFormat, default yyyy-MM-dd.

func (*Container) AddSDTDropdown added in v0.9.0

func (c *Container) AddSDTDropdown(alias, tag string, options map[string]string) *SDT

AddSDTDropdown appends a drop-down list (w:dropDownList + w:listItem). options maps value → display text; keys are written in sorted order.

func (*Container) AddSDTText added in v0.9.0

func (c *Container) AddSDTText(alias, tag, placeholderText string) *SDT

AddSDTText appends a plain-text content control (w:text).

func (*Container) AddShape

func (c *Container) AddShape(typ string, s ...style.Shape) *Shape

AddShape appends a VML shape.

func (*Container) AddTOC

func (c *Container) AddTOC(font any, tocStyle any, minDepth, maxDepth int) *TOC

AddTOC appends a table of contents field.

func (*Container) AddTable

func (c *Container) AddTable(styles ...any) *Table

AddTable appends a table.

func (*Container) AddText

func (c *Container) AddText(text string, styles ...any) *Text

AddText appends a text run wrapped in a paragraph (PHPWord addText).

func (*Container) AddTextBox

func (c *Container) AddTextBox(s ...style.TextBox) *TextBox

AddTextBox appends a text box.

func (*Container) AddTextBreak

func (c *Container) AddTextBreak(count ...int)

AddTextBreak inserts count empty paragraphs (default 1).

func (*Container) AddTextRun

func (c *Container) AddTextRun(styles ...any) *TextRun

AddTextRun appends a rich-text paragraph.

func (*Container) AddTitle

func (c *Container) AddTitle(text string, depth int, page ...int) *Title

AddTitle appends a heading. An optional page number is accepted (PHPWord addTitle).

func (*Container) AppendElement added in v0.12.0

func (c *Container) AppendElement(el Element)

AppendElement appends an existing element and updates its parent.

func (*Container) CommentOn added in v0.4.0

func (c *Container) CommentOn(text, body, author string, extras ...string) *Text

CommentOn adds visible text annotated with a comment (author, body). extras is optional initials then date (ISO-8601).

func (*Container) CountElements

func (c *Container) CountElements() int

CountElements returns the number of children (PHPWord countElements).

func (*Container) Elements

func (c *Container) Elements() []Element

Elements returns child elements in document order.

func (*Container) GetElement

func (c *Container) GetElement(index int) Element

GetElement returns the child at index, or nil.

func (*Container) GetElements

func (c *Container) GetElements() []Element

GetElements is the PHPWord name for Elements.

func (*Container) RemoveElement

func (c *Container) RemoveElement(toRemove any)

RemoveElement removes a child by index or by identity (PHPWord removeElement).

func (*Container) Type

func (c *Container) Type() string

type DMLShape added in v0.8.0

type DMLShape struct {
	Container
	PrstGeom  string
	Width     int
	Height    int
	FillColor string
	LineColor string
	LineWidth int
}

DMLShape is a DrawingML wordprocessing shape (wps:wsp).

func (*DMLShape) Type added in v0.8.0

func (s *DMLShape) Type() string

type Element

type Element interface {
	Type() string
	Parent() Element
	// contains filtered or unexported methods
}

Element is a document-model node.

func CloneElement added in v0.8.0

func CloneElement(el Element) Element

CloneElement returns a deep copy of el (or nil).

type Endnote

type Endnote struct {
	Container
	NoteID int
}

Endnote is an endnote container.

func NewEndnote

func NewEndnote(para any) *Endnote

func (*Endnote) Type

func (e *Endnote) Type() string

type Field

type Field struct {
	Base
	FieldType  string
	Properties map[string]string
	Options    []string
	Text       string
	FontStyle  any
}

Field is a Word field (PAGE, DATE, ...).

func NewField

func NewField(typ string, props map[string]string, options []string, text string) *Field

func (*Field) Type

func (f *Field) Type() string
type Footer struct {
	Container
	HeaderType string
}

Footer is a footer part.

func (*Footer) EvenPage

func (f *Footer) EvenPage() string

func (*Footer) FirstPage

func (f *Footer) FirstPage() string

func (*Footer) GetType

func (f *Footer) GetType() string

func (*Footer) ResetType

func (f *Footer) ResetType() string

func (*Footer) SetType

func (f *Footer) SetType(t string)

func (*Footer) Type

func (f *Footer) Type() string

type Footnote

type Footnote struct {
	Container
	NoteID int
}

Footnote is a footnote container.

func NewFootnote

func NewFootnote(para any) *Footnote

func (*Footnote) Type

func (f *Footnote) Type() string

type FormField

type FormField struct {
	Text
	FormType string // textinput, checkbox, dropdown
	Name     string
	Value    string
	Default  string
	Enabled  bool
	Items    []string
}

FormField is a Word form field.

func NewFormField

func NewFormField(typ string, font, para any) *FormField

func (*FormField) Type

func (f *FormField) Type() string

type Formula

type Formula struct {
	Base
	Math   *math.Math
	Source string
}

Formula is an OMML equation.

func (*Formula) Type

func (f *Formula) Type() string
type Header struct {
	Container
	HeaderType string
}

Header is a header part.

func (*Header) AddTextWatermark added in v0.5.0

func (h *Header) AddTextWatermark(text string) *TextWatermark

AddTextWatermark appends a VML text watermark to a header.

func (*Header) AddWatermark

func (h *Header) AddWatermark(src string, st ...any) *Image

AddWatermark appends a watermark image to a header (PHPWord Header::addWatermark).

func (*Header) AddWatermarkBytes added in v0.5.0

func (h *Header) AddWatermarkBytes(name string, data []byte, st ...any) *Image

AddWatermarkBytes appends an in-memory image watermark to a header.

func (*Header) EnsureImageWatermark added in v0.5.0

func (h *Header) EnsureImageWatermark(data []byte, name ...string) *Image

EnsureImageWatermark sets or updates the header's image watermark.

func (*Header) EnsureTextWatermark added in v0.5.0

func (h *Header) EnsureTextWatermark(text string) *TextWatermark

EnsureTextWatermark sets or updates the header's text watermark.

func (*Header) EvenPage

func (h *Header) EvenPage() string

func (*Header) FirstPage

func (h *Header) FirstPage() string

func (*Header) GetType

func (h *Header) GetType() string

func (*Header) ResetType

func (h *Header) ResetType() string

func (*Header) SetType

func (h *Header) SetType(t string)

func (*Header) Type

func (h *Header) Type() string

type Image

type Image struct {
	Base
	Source      string
	Data        []byte
	Style       style.Image
	IsWatermark bool
	Media       Media
}

Image is a picture (PHPWord Element\Image).

func NewImage

func NewImage(source string, st any) *Image

NewImage constructs an image from a path.

func NewImageBytes

func NewImageBytes(name string, data []byte, st any) *Image

NewImageBytes constructs an image from memory.

func (*Image) GetAltText

func (i *Image) GetAltText() string

func (*Image) GetName

func (i *Image) GetName() string

func (*Image) GetSource

func (i *Image) GetSource() string

func (*Image) SetAltText

func (i *Image) SetAltText(s string)

func (*Image) SetIsWatermark

func (i *Image) SetIsWatermark(v bool)

func (*Image) SetName

func (i *Image) SetName(name string)

func (*Image) Type

func (i *Image) Type() string

type Line

type Line struct {
	Base
	Style style.Line
}

Line is a VML line.

func (*Line) Type

func (l *Line) Type() string
type Link struct {
	Base
	Target         string
	Text           string
	Internal       bool
	FontStyle      any
	ParagraphStyle any
}

Link is a hyperlink (PHPWord Element\Link).

func NewLink(target, text string, font, para any, internal bool) *Link

NewLink constructs a hyperlink.

func (*Link) Type

func (l *Link) Type() string

type ListItem

type ListItem struct {
	Base
	Text           string
	Depth          int
	FontStyle      any
	ParagraphStyle any
	ListStyle      any
}

ListItem is a numbered or bulleted paragraph.

func NewListItem

func NewListItem(text string, depth int, font, list, para any) *ListItem

NewListItem constructs a list paragraph.

func (*ListItem) Type

func (l *ListItem) Type() string

type ListItemRun

type ListItemRun struct {
	TextRun
	Depth     int
	ListStyle any
}

ListItemRun is a rich list paragraph.

func NewListItemRun

func NewListItemRun(depth int, list, para any) *ListItemRun

NewListItemRun constructs a rich list paragraph.

func (*ListItemRun) Type

func (l *ListItemRun) Type() string

type Media

type Media struct {
	MediaType string // image, object
	Target    string
	Source    string
	Data      []byte
	Ext       string
	IsURL     bool
}

Media holds binary media attached to an image or OLE object.

type OLEObject

type OLEObject struct {
	Base
	Source string
	Style  style.Image
	Media  Media
}

OLEObject is an embedded OLE object.

func NewOLEObject

func NewOLEObject(source string, st any) *OLEObject

func (*OLEObject) Type

func (o *OLEObject) Type() string

type PageBreak

type PageBreak struct{ Base }

PageBreak is a page break.

func (*PageBreak) Type

func (p *PageBreak) Type() string

type PreserveText

type PreserveText struct {
	Text
}

PreserveText is a field character run used in headers.

func NewPreserveText

func NewPreserveText(text string, font, para any) *PreserveText

func (*PreserveText) Type

func (p *PreserveText) Type() string

type Row

type Row struct {
	Base
	Style style.Row
	Cells []*Cell
}

Row is a table row.

func (*Row) AddCell

func (r *Row) AddCell(width int, st ...any) *Cell

AddCell appends a cell with width in twips.

func (*Row) GetCells

func (r *Row) GetCells() []*Cell

GetCells returns the row's cells.

func (*Row) GetHeight

func (r *Row) GetHeight() int

GetHeight returns the row height in twips.

func (*Row) IsCantSplit added in v0.9.0

func (r *Row) IsCantSplit() bool

IsCantSplit reports whether the row is marked w:cantSplit.

func (*Row) IsHeader added in v0.9.0

func (r *Row) IsHeader() bool

IsHeader reports whether the row is a repeating table header.

func (*Row) SetCantSplit added in v0.9.0

func (r *Row) SetCantSplit(v bool) *Row

SetCantSplit toggles keeping the row on one page (w:cantSplit).

func (*Row) SetHeader added in v0.9.0

func (r *Row) SetHeader(v bool) *Row

SetHeader toggles repeating this row at the top of each page (w:tblHeader).

func (*Row) Type

func (r *Row) Type() string

type Ruby

type Ruby struct {
	Base
	BaseText   *TextRun
	RubyText   *TextRun
	Properties RubyProperties
}

Ruby is phonetic guide text.

func (*Ruby) Type

func (r *Ruby) Type() string

type RubyProperties

type RubyProperties struct {
	Alignment    string
	Hanging      int
	FontFace     string
	FontSize     float64
	Raise        float64
	BaseFontSize float64
	LanguageID   string
}

RubyProperties controls ruby layout.

type SDT

type SDT struct {
	Container
	SDTType       string
	Alias         string
	Tag           string
	Value         string
	Placeholder   string
	DateFormat    string
	Locale        string
	Lock          string
	ID            int
	Checked       bool
	ShowingPlcHdr bool
	MultiLine     bool
	ListItems     []SDTListItem
}

SDT is a structured document tag (w:sdt).

Child order in the package is w:sdt → w:sdtPr → w:sdtContent (CT_SdtBlock / CT_SdtRun).

func (*SDT) SetAlias added in v0.9.0

func (s *SDT) SetAlias(alias string) *SDT

SetAlias sets w:alias.

func (*SDT) SetChecked added in v0.9.0

func (s *SDT) SetChecked(checked bool) *SDT

SetChecked sets the w14:checkbox state and the content glyph.

func (*SDT) SetDateFormat added in v0.9.0

func (s *SDT) SetDateFormat(format string) *SDT

SetDateFormat sets w:dateFormat (for example yyyy-MM-dd).

func (*SDT) SetListItems added in v0.9.0

func (s *SDT) SetListItems(items []SDTListItem) *SDT

SetListItems replaces drop-down / combo-box entries.

func (*SDT) SetTag added in v0.9.0

func (s *SDT) SetTag(tag string) *SDT

SetTag sets w:tag.

func (*SDT) SetValue added in v0.9.0

func (s *SDT) SetValue(value string) *SDT

SetValue sets the visible sdtContent text.

func (*SDT) Type

func (s *SDT) Type() string

type SDTListItem added in v0.9.0

type SDTListItem struct {
	Value       string
	DisplayText string
}

SDTListItem is one w:listItem on a drop-down or combo box.

type Section

type Section struct {
	Container
	Style              style.Section
	Headers            []*Header
	Footers            []*Footer
	FootnoteProperties *metadata.FootnoteProperties
}

Section is a document section (PHPWord Element\Section).

func CloneSection added in v0.8.0

func CloneSection(s *Section) *Section

CloneSection returns a deep copy of a section, including headers and footers.

func NewSection

func NewSection(index int, st any) *Section

NewSection constructs a section with the given 1-based index.

func (*Section) AddFooter

func (s *Section) AddFooter(typ ...string) *Footer

AddFooter appends a footer of the given type.

func (*Section) AddHeader

func (s *Section) AddHeader(typ ...string) *Header

AddHeader appends a header of the given type (default, first, even).

func (*Section) GetFooters

func (s *Section) GetFooters() []*Footer

GetFooters returns section footers.

func (*Section) GetFootnoteProperties

func (s *Section) GetFootnoteProperties() *metadata.FootnoteProperties

GetFootnoteProperties returns section footnote properties.

func (*Section) GetHeaders

func (s *Section) GetHeaders() []*Header

GetHeaders returns section headers.

func (*Section) HasDifferentEvenPage added in v0.5.0

func (s *Section) HasDifferentEvenPage() bool

HasDifferentEvenPage reports whether an even-page header or footer exists.

func (*Section) HasDifferentFirstPage

func (s *Section) HasDifferentFirstPage() bool

HasDifferentFirstPage reports whether a first-page header or footer exists.

func (*Section) SetColumns added in v0.8.0

func (s *Section) SetColumns(num int, space int, showLine bool)

SetColumns sets section multi-column layout (w:cols num/space/sep).

func (*Section) SetDifferentFirstPage added in v0.5.0

func (s *Section) SetDifferentFirstPage(enable bool)

SetDifferentFirstPage adds a first-page header when enable is true.

func (*Section) SetFootnoteProperties

func (s *Section) SetFootnoteProperties(p *metadata.FootnoteProperties)

SetFootnoteProperties sets section footnote properties.

func (*Section) SetOrientation added in v0.5.0

func (s *Section) SetOrientation(orient string)

SetOrientation sets portrait or landscape page orientation.

func (*Section) Type

func (s *Section) Type() string

type Shape

type Shape struct {
	Base
	ShapeType string
	Style     style.Shape
}

Shape is a VML shape.

func (*Shape) Type

func (s *Shape) Type() string

type TOC

type TOC struct {
	Base
	FontStyle any
	TOCStyle  any
	MinDepth  int
	MaxDepth  int
}

TOC is a table of contents field.

func (*TOC) Type

func (t *TOC) Type() string

type Table

type Table struct {
	Base
	Style style.Table
	Rows  []*Row
	Width int
}

Table is a table element (PHPWord Element\Table).

func NewTable

func NewTable(st any) *Table

NewTable constructs a table.

func (*Table) AddCell

func (t *Table) AddCell(width int, st ...any) *Cell

AddCell is a PHPWord convenience that adds a cell to the last row, creating a row if needed.

func (*Table) AddRow

func (t *Table) AddRow(height ...int) *Row

AddRow appends a row with optional height in twips.

func (*Table) AllowEdit added in v0.9.0

func (t *Table) AllowEdit(groupOrUser string) *Table

AllowEdit marks this table as an exception range in a protected document.

func (*Table) CountColumns

func (t *Table) CountColumns() int

CountColumns returns the maximum number of columns, counting grid spans.

func (*Table) FindFirstDefinedCellWidths

func (t *Table) FindFirstDefinedCellWidths() []int

FindFirstDefinedCellWidths returns the first row's cell widths.

func (*Table) GetRows

func (t *Table) GetRows() []*Row

GetRows returns table rows.

func (*Table) GetWidth

func (t *Table) GetWidth() int

GetWidth returns the table width in twips.

func (*Table) SetHeaderRow added in v0.9.0

func (t *Table) SetHeaderRow(row *Row) *Table

SetHeaderRow marks row as a repeating header (w:tblHeader). Word repeats consecutive header rows at the start of the table on each page.

func (*Table) SetWidth

func (t *Table) SetWidth(w int)

SetWidth sets the table width in twips (PHPWord Table::setWidth).

func (*Table) Type

func (t *Table) Type() string

type Text

type Text struct {
	Base
	Content        string
	FontStyle      any // string name or style.Font
	ParagraphStyle any // string name or style.Paragraph
}

Text is a paragraph containing a single run (PHPWord Element\Text).

func NewText

func NewText(text string, font, para any) *Text

NewText constructs a text element.

func (*Text) AllowEdit added in v0.9.0

func (t *Text) AllowEdit(groupOrUser string) *Text

AllowEdit marks this paragraph as an exception range in a protected document.

func (*Text) Font

func (t *Text) Font() *style.Font

func (*Text) FontName

func (t *Text) FontName() string

func (*Text) Paragraph

func (t *Text) Paragraph() *style.Paragraph

func (*Text) ParagraphName

func (t *Text) ParagraphName() string

func (*Text) SetText

func (t *Text) SetText(s string)

func (*Text) Text

func (t *Text) Text() string

func (*Text) Type

func (t *Text) Type() string

type TextBox

type TextBox struct {
	Container
	BoxStyle style.TextBox
}

TextBox is a floating text frame.

func NewTextBox

func NewTextBox() *TextBox

func (*TextBox) Type

func (t *TextBox) Type() string

type TextBreak

type TextBreak struct{ Base }

TextBreak is an empty paragraph, or a line break inside a TextRun.

func (*TextBreak) Type

func (t *TextBreak) Type() string

type TextRun

type TextRun struct {
	Container
	ParagraphStyle any
}

TextRun is a paragraph that holds inline elements (PHPWord Element\TextRun).

func NewTextRun

func NewTextRun(para any) *TextRun

NewTextRun constructs an empty run container.

func (*TextRun) AddText

func (t *TextRun) AddText(text string, styles ...any) *Text

AddText appends an inline run (no paragraph of its own).

func (*TextRun) AllowEdit added in v0.9.0

func (t *TextRun) AllowEdit(groupOrUser string) *TextRun

AllowEdit marks this rich paragraph as an exception range in a protected document.

func (*TextRun) GetParagraphStyle

func (t *TextRun) GetParagraphStyle() any

GetParagraphStyle returns the paragraph style.

func (*TextRun) GetText

func (t *TextRun) GetText() string

GetText concatenates child text (PHPWord TextRun::getText).

func (*TextRun) SetParagraphStyle

func (t *TextRun) SetParagraphStyle(para any)

SetParagraphStyle sets the paragraph style of this run.

func (*TextRun) Type

func (t *TextRun) Type() string

type TextWatermark added in v0.5.0

type TextWatermark struct {
	Base
	Text     string
	Angle    float64 // degrees; 0 means default -45
	Color    string  // VML fillcolor (silver or #RRGGBB)
	FontName string
	FontSize int     // points; 0 means 1pt + fitshape
	Opacity  float64 // 0–1; 0 means default 0.5
	Tile     bool
	TileRows int
	TileCols int
}

TextWatermark is a VML text watermark drawn in a header.

func (*TextWatermark) Type added in v0.5.0

func (t *TextWatermark) Type() string

type Title

type Title struct {
	Base
	Text         string
	Depth        int
	Page         int
	Run          *TextRun
	BookmarkName string
}

Title is a heading paragraph.

func NewTitle

func NewTitle(text string, depth int) *Title

NewTitle constructs a heading.

func (*Title) Type

func (t *Title) Type() string

type TrackChange

type TrackChange struct {
	Base
	ChangeType string // ins, del
	Author     string
	Date       string
}

TrackChange marks an insertion or deletion.

func (*TrackChange) Type

func (t *TrackChange) Type() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL