Documentation
¶
Index ¶
- Constants
- func CheckboxFont() string
- func NormalizeSDTType(typ string) string
- func ParseAllowEdit(groupOrUser string) (edGrp, ed string)
- type Base
- func (b *Base) GetCommentRangeEnd() *Comment
- func (b *Base) GetCommentRangeStart() *Comment
- func (b *Base) GetTrackChange() *TrackChange
- func (b *Base) HasAllowEdit() bool
- func (b *Base) Parent() Element
- func (b *Base) SetChangeInfo(typ, author, date string)
- func (b *Base) SetCommentRangeEnd(c *Comment)
- func (b *Base) SetCommentRangeStart(c *Comment)
- func (b *Base) SetTrackChange(tc *TrackChange)
- type Bookmark
- type Cell
- func (c *Cell) AllowEdit(groupOrUser string) *Cell
- func (c *Cell) SetBorder(side, borderStyle string, size int, color string)
- func (c *Cell) SetPadding(top, left, bottom, right int)
- func (c *Cell) SetTextDirection(v string) *Cell
- func (c *Cell) SetVAlign(v string) *Cell
- func (c *Cell) SetVerticalAlignment(v string)
- func (c *Cell) Type() string
- type Chart
- func (c *Chart) AddComboSeries(kind string, categories []string, values []float64, name string, ...)
- func (c *Chart) AddSeries(categories []string, values []float64, name ...string)
- func (c *Chart) SetDataLabels(opts style.DataLabelOptions)
- func (c *Chart) SetLegendPosition(pos string)
- func (c *Chart) SetLineMarker(symbol string)
- func (c *Chart) SetLineSmooth(on bool)
- func (c *Chart) SetMajorGridlines(visible bool)
- func (c *Chart) Type() string
- type ChartSeries
- type CheckBox
- type Comment
- type Container
- func (c *Container) AddBookmark(name string) *Bookmark
- func (c *Container) AddChart(typ string, categories []string, values []float64, s ...style.Chart) *Chart
- func (c *Container) AddCheckBox(name, text string, styles ...any) *CheckBox
- func (c *Container) AddComment(author, initials, date string) *Comment
- func (c *Container) AddDMLShape(prst string, width, height int, fill, line string, lineWidth int) *DMLShape
- func (c *Container) AddDeletion(text, author, date string, styles ...any) *Text
- func (c *Container) AddEndnote(styles ...any) *Endnote
- func (c *Container) AddField(typ string, properties map[string]string, options []string, text string) *Field
- func (c *Container) AddFootnote(styles ...any) *Footnote
- func (c *Container) AddFormField(typ string, styles ...any) *FormField
- func (c *Container) AddFormula(m *math.Math) *Formula
- func (c *Container) AddImage(source string, styles ...any) *Image
- func (c *Container) AddImageBytes(name string, data []byte, styles ...any) *Image
- func (c *Container) AddInsertion(text, author, date string, styles ...any) *Text
- func (c *Container) AddLine(s ...style.Line) *Line
- func (c *Container) AddLink(target, text string, styles ...any) *Link
- func (c *Container) AddListItem(text string, depth int, styles ...any) *ListItem
- func (c *Container) AddListItemRun(depth int, listStyle any, para any) *ListItemRun
- func (c *Container) AddMath(formula string) *Formula
- func (c *Container) AddNumPages() *Field
- func (c *Container) AddOLEObject(source string, styles ...any) *OLEObject
- func (c *Container) AddObject(source string, styles ...any) *OLEObject
- func (c *Container) AddPageBreak() *PageBreak
- func (c *Container) AddPageNumber() *Field
- func (c *Container) AddPreserveText(text string, styles ...any) *PreserveText
- func (c *Container) AddRuby(base, ruby *TextRun, props RubyProperties) *Ruby
- func (c *Container) AddSDT(typ string) *SDT
- func (c *Container) AddSDTCheckbox(alias, tag string, checked bool) *SDT
- func (c *Container) AddSDTDate(alias, tag, dateFormat string) *SDT
- func (c *Container) AddSDTDropdown(alias, tag string, options map[string]string) *SDT
- func (c *Container) AddSDTText(alias, tag, placeholderText string) *SDT
- func (c *Container) AddShape(typ string, s ...style.Shape) *Shape
- func (c *Container) AddTOC(font any, tocStyle any, minDepth, maxDepth int) *TOC
- func (c *Container) AddTable(styles ...any) *Table
- func (c *Container) AddText(text string, styles ...any) *Text
- func (c *Container) AddTextBox(s ...style.TextBox) *TextBox
- func (c *Container) AddTextBreak(count ...int)
- func (c *Container) AddTextRun(styles ...any) *TextRun
- func (c *Container) AddTitle(text string, depth int, page ...int) *Title
- func (c *Container) AppendElement(el Element)
- func (c *Container) CommentOn(text, body, author string, extras ...string) *Text
- func (c *Container) CountElements() int
- func (c *Container) Elements() []Element
- func (c *Container) GetElement(index int) Element
- func (c *Container) GetElements() []Element
- func (c *Container) RemoveElement(toRemove any)
- func (c *Container) Type() string
- type DMLShape
- type Element
- type Endnote
- type Field
- type Footer
- type Footnote
- type FormField
- type Formula
- type Header
- func (h *Header) AddTextWatermark(text string) *TextWatermark
- func (h *Header) AddWatermark(src string, st ...any) *Image
- func (h *Header) AddWatermarkBytes(name string, data []byte, st ...any) *Image
- func (h *Header) EnsureImageWatermark(data []byte, name ...string) *Image
- func (h *Header) EnsureTextWatermark(text string) *TextWatermark
- func (h *Header) EvenPage() string
- func (h *Header) FirstPage() string
- func (h *Header) GetType() string
- func (h *Header) ResetType() string
- func (h *Header) SetType(t string)
- func (h *Header) Type() string
- type Image
- type Line
- type Link
- type ListItem
- type ListItemRun
- type Media
- type OLEObject
- type PageBreak
- type PreserveText
- type Row
- type Ruby
- type RubyProperties
- type SDT
- type SDTListItem
- type Section
- func (s *Section) AddFooter(typ ...string) *Footer
- func (s *Section) AddHeader(typ ...string) *Header
- func (s *Section) GetFooters() []*Footer
- func (s *Section) GetFootnoteProperties() *metadata.FootnoteProperties
- func (s *Section) GetHeaders() []*Header
- func (s *Section) HasDifferentEvenPage() bool
- func (s *Section) HasDifferentFirstPage() bool
- func (s *Section) SetColumns(num int, space int, showLine bool)
- func (s *Section) SetDifferentFirstPage(enable bool)
- func (s *Section) SetFootnoteProperties(p *metadata.FootnoteProperties)
- func (s *Section) SetOrientation(orient string)
- func (s *Section) Type() string
- type Shape
- type TOC
- type Table
- func (t *Table) AddCell(width int, st ...any) *Cell
- func (t *Table) AddRow(height ...int) *Row
- func (t *Table) AllowEdit(groupOrUser string) *Table
- func (t *Table) CountColumns() int
- func (t *Table) FindFirstDefinedCellWidths() []int
- func (t *Table) GetRows() []*Row
- func (t *Table) GetWidth() int
- func (t *Table) SetHeaderRow(row *Row) *Table
- func (t *Table) SetWidth(w int)
- func (t *Table) Type() string
- type Text
- type TextBox
- type TextBreak
- type TextRun
- type TextWatermark
- type Title
- type TrackChange
Constants ¶
const ( RubyAlignCenter = "center" RubyAlignDistributeLetter = "distributeLetter" RubyAlignDistributeSpace = "distributeSpace" RubyAlignLeft = "left" RubyAlignRight = "right" RubyAlignRightVertical = "rightVertical" )
Ruby alignment values (PHPWord ComplexType\RubyProperties).
const ( EdGrpNone = "none" EdGrpEveryone = "everyone" EdGrpAdministrators = "administrators" EdGrpContributors = "contributors" EdGrpEditors = "editors" EdGrpOwners = "owners" EdGrpCurrent = "current" )
ST_EdGrp values used on w:permStart.
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.
const ( SDTCheckboxUnchecked = "\u2610" // ☐ SDTCheckboxChecked = "\u2612" // ☒ )
Checkbox glyphs used in w:sdtContent (Word 2010 w14:checkbox).
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
NormalizeSDTType maps PHPWord / shorthand type names onto the OpenXML control kind.
func ParseAllowEdit ¶ added in v0.9.0
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 (*Base) GetCommentRangeStart ¶
func (*Base) GetTrackChange ¶
func (b *Base) GetTrackChange() *TrackChange
func (*Base) HasAllowEdit ¶ added in v0.9.0
HasAllowEdit reports whether a permission range should be written.
func (*Base) SetChangeInfo ¶
func (*Base) SetCommentRangeEnd ¶
func (*Base) SetCommentRangeStart ¶
func (*Base) SetTrackChange ¶
func (b *Base) SetTrackChange(tc *TrackChange)
type Cell ¶
Cell is a table cell and a container.
func (*Cell) AllowEdit ¶ added in v0.9.0
AllowEdit marks this cell's contents as an exception range in a protected document.
func (*Cell) SetBorder ¶ added in v0.6.0
SetBorder sets one cell border (side: top, left, bottom, right, or all).
func (*Cell) SetPadding ¶ added in v0.6.0
SetPadding sets cell inner margins in twips (w:tcMar).
func (*Cell) SetTextDirection ¶ added in v0.6.0
SetTextDirection sets w:textDirection (lrTb, tbRl, btLr, …) and returns the cell.
func (*Cell) SetVAlign ¶ added in v0.9.0
SetVAlign sets w:vAlign (top, center, bottom) and returns the cell.
func (*Cell) SetVerticalAlignment ¶ added in v0.6.0
SetVerticalAlignment sets w:vAlign (top, center, bottom).
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) 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
SetLegendPosition shows the legend at pos (t/b/l/r).
func (*Chart) SetLineMarker ¶ added in v0.7.0
SetLineMarker sets the c:marker symbol for line series (circle, diamond, none, …).
func (*Chart) SetLineSmooth ¶ added in v0.7.0
SetLineSmooth enables c:smooth on line series.
func (*Chart) SetMajorGridlines ¶ added in v0.7.0
SetMajorGridlines toggles major gridlines on both axes.
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 Comment ¶
type Comment struct {
Container
Author string
Initials string
Date string
CommentID int
StartElement Element
EndElement Element
}
Comment is a comment range.
type Container ¶
Container is a parent that holds child elements (section, cell, textrun, ...).
func (*Container) AddBookmark ¶
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 ¶
AddCheckBox appends a checkbox form field.
func (*Container) AddComment ¶
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
AddDeletion appends text marked as a tracked deletion (w:del).
func (*Container) AddEndnote ¶
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 ¶
AddFootnote appends a footnote.
func (*Container) AddFormField ¶
AddFormField appends a form field of the given type.
func (*Container) AddFormula ¶
AddFormula appends an OMML formula.
func (*Container) AddImageBytes ¶
AddImageBytes appends an image from memory.
func (*Container) AddInsertion ¶ added in v0.4.0
AddInsertion appends text marked as a tracked insertion (w:ins).
func (*Container) AddListItem ¶
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
AddMath parses a basic LaTeX expression into a native OMML formula.
func (*Container) AddNumPages ¶ added in v0.5.0
AddNumPages inserts a NUMPAGES field.
func (*Container) AddOLEObject ¶
AddOLEObject appends an embedded OLE object.
func (*Container) AddPageBreak ¶
AddPageBreak inserts a page break.
func (*Container) AddPageNumber ¶ added in v0.5.0
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) AddSDTCheckbox ¶ added in v0.9.0
AddSDTCheckbox appends a Word 2010 checkbox (w14:checkbox).
func (*Container) AddSDTDate ¶ added in v0.9.0
AddSDTDate appends a date picker (w:date). dateFormat is w:dateFormat, default yyyy-MM-dd.
func (*Container) AddSDTDropdown ¶ added in v0.9.0
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
AddSDTText appends a plain-text content control (w:text).
func (*Container) AddTextBox ¶
AddTextBox appends a text box.
func (*Container) AddTextBreak ¶
AddTextBreak inserts count empty paragraphs (default 1).
func (*Container) AddTextRun ¶
AddTextRun appends a rich-text paragraph.
func (*Container) AddTitle ¶
AddTitle appends a heading. An optional page number is accepted (PHPWord addTitle).
func (*Container) AppendElement ¶ added in v0.12.0
AppendElement appends an existing element and updates its parent.
func (*Container) CommentOn ¶ added in v0.4.0
CommentOn adds visible text annotated with a comment (author, body). extras is optional initials then date (ISO-8601).
func (*Container) CountElements ¶
CountElements returns the number of children (PHPWord countElements).
func (*Container) GetElement ¶
GetElement returns the child at index, or nil.
func (*Container) GetElements ¶
GetElements is the PHPWord name for Elements.
func (*Container) RemoveElement ¶
RemoveElement removes a child by index or by identity (PHPWord removeElement).
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).
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
CloneElement returns a deep copy of el (or nil).
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, ...).
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 ¶
type Header ¶
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 ¶
AddWatermark appends a watermark image to a header (PHPWord Header::addWatermark).
func (*Header) AddWatermarkBytes ¶ added in v0.5.0
AddWatermarkBytes appends an in-memory image watermark to a header.
func (*Header) EnsureImageWatermark ¶ added in v0.5.0
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.
type Image ¶
Image is a picture (PHPWord Element\Image).
func NewImageBytes ¶
NewImageBytes constructs an image from memory.
func (*Image) GetAltText ¶
func (*Image) SetAltText ¶
func (*Image) SetIsWatermark ¶
type Link ¶
Link is a hyperlink (PHPWord Element\Link).
type ListItem ¶
ListItem is a numbered or bulleted paragraph.
func NewListItem ¶
NewListItem constructs a list paragraph.
type ListItemRun ¶
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 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 ¶
Row is a table row.
func (*Row) IsCantSplit ¶ added in v0.9.0
IsCantSplit reports whether the row is marked w:cantSplit.
func (*Row) IsHeader ¶ added in v0.9.0
IsHeader reports whether the row is a repeating table header.
func (*Row) SetCantSplit ¶ added in v0.9.0
SetCantSplit toggles keeping the row on one page (w:cantSplit).
type Ruby ¶
type Ruby struct {
Base
BaseText *TextRun
RubyText *TextRun
Properties RubyProperties
}
Ruby is phonetic guide text.
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) SetChecked ¶ added in v0.9.0
SetChecked sets the w14:checkbox state and the content glyph.
func (*SDT) SetDateFormat ¶ added in v0.9.0
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.
type SDTListItem ¶ added in v0.9.0
SDTListItem is one w:listItem on a drop-down or combo box.
type Section ¶
type Section struct {
Container
Style style.Section
Headers []*Header
FootnoteProperties *metadata.FootnoteProperties
}
Section is a document section (PHPWord Element\Section).
func CloneSection ¶ added in v0.8.0
CloneSection returns a deep copy of a section, including headers and footers.
func NewSection ¶
NewSection constructs a section with the given 1-based index.
func (*Section) GetFooters ¶
GetFooters returns section footers.
func (*Section) GetFootnoteProperties ¶
func (s *Section) GetFootnoteProperties() *metadata.FootnoteProperties
GetFootnoteProperties returns section footnote properties.
func (*Section) GetHeaders ¶
GetHeaders returns section headers.
func (*Section) HasDifferentEvenPage ¶ added in v0.5.0
HasDifferentEvenPage reports whether an even-page header or footer exists.
func (*Section) HasDifferentFirstPage ¶
HasDifferentFirstPage reports whether a first-page header or footer exists.
func (*Section) SetColumns ¶ added in v0.8.0
SetColumns sets section multi-column layout (w:cols num/space/sep).
func (*Section) SetDifferentFirstPage ¶ added in v0.5.0
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
SetOrientation sets portrait or landscape page orientation.
type Table ¶
Table is a table element (PHPWord Element\Table).
func (*Table) AddCell ¶
AddCell is a PHPWord convenience that adds a cell to the last row, creating a row if needed.
func (*Table) AllowEdit ¶ added in v0.9.0
AllowEdit marks this table as an exception range in a protected document.
func (*Table) CountColumns ¶
CountColumns returns the maximum number of columns, counting grid spans.
func (*Table) FindFirstDefinedCellWidths ¶
FindFirstDefinedCellWidths returns the first row's cell widths.
func (*Table) SetHeaderRow ¶ added in v0.9.0
SetHeaderRow marks row as a repeating header (w:tblHeader). Word repeats consecutive header rows at the start of the table on each page.
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 (*Text) AllowEdit ¶ added in v0.9.0
AllowEdit marks this paragraph as an exception range in a protected document.
func (*Text) ParagraphName ¶
type TextBreak ¶
type TextBreak struct{ Base }
TextBreak is an empty paragraph, or a line break inside a TextRun.
type TextRun ¶
TextRun is a paragraph that holds inline elements (PHPWord Element\TextRun).
func (*TextRun) AllowEdit ¶ added in v0.9.0
AllowEdit marks this rich paragraph as an exception range in a protected document.
func (*TextRun) GetParagraphStyle ¶
GetParagraphStyle returns the paragraph style.
func (*TextRun) SetParagraphStyle ¶
SetParagraphStyle sets the paragraph style of this run.
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 TrackChange ¶
TrackChange marks an insertion or deletion.
func (*TrackChange) Type ¶
func (t *TrackChange) Type() string