Documentation
¶
Index ¶
- func CreateMinimalDocx(outputPath string) error
- type Body
- type Bold
- type Break
- type Color
- type ContentTypes
- type Document
- func (d *Document) AddParagraph(text string, opts ...ParagraphOption)
- func (d *Document) AddParagraphAt(index int, text string, opts ...ParagraphOption) error
- func (d *Document) AddTable(rows, cols int) *Table
- func (d *Document) Clear()
- func (d *Document) Clone() *Document
- func (d *Document) DeleteParagraph(index int) error
- func (d *Document) DeleteParagraphsRange(start, end int) error
- func (d *Document) DeleteTable(index int) error
- func (d *Document) FindText(searchText string) []int
- func (d *Document) GetParagraphCount() int
- func (d *Document) GetParagraphText(index int) (string, error)
- func (d *Document) GetTableCount() int
- func (d *Document) GetText() string
- func (d *Document) ReplaceText(oldText, newText string) int
- func (d *Document) ReplaceTextInParagraph(index int, oldText, newText string) (int, error)
- func (d *Document) Save(filePath string) error
- func (d *Document) SaveAs(filePath string) error
- func (d *Document) ToBytes() ([]byte, error)
- func (d *Document) WriteToZip(w *zip.Writer) error
- type Italic
- type Jc
- type PProps
- type PStyle
- type Paragraph
- type ParagraphOption
- type RProps
- type Relationships
- type Run
- type Size
- type Spacing
- type Styles
- type Tab
- type Table
- type TblCell
- type TblGrid
- type TblGridCol
- type TblPr
- type TblRow
- type TblStyle
- type TblWidth
- type TcPr
- type Text
- type TrPr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateMinimalDocx ¶
CreateMinimalDocx creates a minimal valid .docx file for testing
Types ¶
type Body ¶
type Body struct {
XMLName xml.Name `xml:"body"`
Paragraphs []Paragraph `xml:"p"`
Tables []Table `xml:"tbl"`
}
Body represents the document body
type ContentTypes ¶
ContentTypes represents [Content_Types].xml
type Document ¶
type Document struct {
FilePath string
Body *Body
Styles *Styles
ContentTypes *ContentTypes
Rels *Relationships
// contains filtered or unexported fields
}
Document represents a .docx document structure
func CreateFromTemplate ¶
CreateFromTemplate creates a new document based on a template
func (*Document) AddParagraph ¶
func (d *Document) AddParagraph(text string, opts ...ParagraphOption)
AddParagraph adds a new paragraph to the document
func (*Document) AddParagraphAt ¶
func (d *Document) AddParagraphAt(index int, text string, opts ...ParagraphOption) error
AddParagraphAt inserts a paragraph at a specific index
func (*Document) Clear ¶
func (d *Document) Clear()
Clear removes all paragraphs and tables from the document
func (*Document) DeleteParagraph ¶
DeleteParagraph removes a paragraph by index
func (*Document) DeleteParagraphsRange ¶
DeleteParagraphsRange deletes multiple paragraphs from start to end (inclusive)
func (*Document) DeleteTable ¶
DeleteTable removes a table by index
func (*Document) FindText ¶
FindText searches for text in the document and returns paragraph indices
func (*Document) GetParagraphCount ¶
GetParagraphCount returns the number of paragraphs
func (*Document) GetParagraphText ¶
GetParagraphText returns text from a specific paragraph
func (*Document) GetTableCount ¶
GetTableCount returns the number of tables
func (*Document) ReplaceText ¶
ReplaceText replaces all occurrences of old text with new text
func (*Document) ReplaceTextInParagraph ¶
ReplaceTextInParagraph replaces text in a specific paragraph
type Jc ¶
type Jc struct {
XMLName xml.Name `xml:"jc"`
Val string `xml:"val,attr"` // left, center, right, both
}
Jc represents text justification
type PProps ¶
type PProps struct {
XMLName xml.Name `xml:"pPr"`
Style *PStyle `xml:"pStyle,omitempty"`
Jc *Jc `xml:"jc,omitempty"` // Justification
Spacing *Spacing `xml:"spacing,omitempty"`
}
PProps represents paragraph properties
type Paragraph ¶
type Paragraph struct {
XMLName xml.Name `xml:"p"`
Runs []Run `xml:"r"`
Props *PProps `xml:"pPr,omitempty"`
}
Paragraph represents a paragraph in the document
type ParagraphOption ¶
type ParagraphOption func(*Paragraph)
ParagraphOption is a function type for configuring paragraphs
func WithAlignment ¶
func WithAlignment(align string) ParagraphOption
WithAlignment sets paragraph alignment ("left", "center", "right", "both")
func WithColor ¶
func WithColor(color string) ParagraphOption
WithColor sets the text color (hex without #, e.g., "FF0000" for red)
func WithSize ¶
func WithSize(size string) ParagraphOption
WithSize sets the font size (in half-points, e.g., 24 = 12pt)
type RProps ¶
type RProps struct {
XMLName xml.Name `xml:"rPr"`
Bold *Bold `xml:"b,omitempty"`
Italic *Italic `xml:"i,omitempty"`
Size *Size `xml:"sz,omitempty"`
Color *Color `xml:"color,omitempty"`
}
RProps represents run properties
type Relationships ¶
Relationships represents document relationships
type Run ¶
type Run struct {
XMLName xml.Name `xml:"r"`
Props *RProps `xml:"rPr,omitempty"`
Text []Text `xml:"t"`
Tab *Tab `xml:"tab,omitempty"`
Break *Break `xml:"br,omitempty"`
}
Run represents a text run
type Spacing ¶
type Spacing struct {
XMLName xml.Name `xml:"spacing"`
Before string `xml:"before,attr,omitempty"`
After string `xml:"after,attr,omitempty"`
Line string `xml:"line,attr,omitempty"`
}
Spacing represents paragraph spacing
type Table ¶
type Table struct {
XMLName xml.Name `xml:"tbl"`
Props *TblPr `xml:"tblPr,omitempty"`
Grid *TblGrid `xml:"tblGrid,omitempty"`
Rows []TblRow `xml:"tr"`
}
Table represents a table in the document
func (*Table) GetCellText ¶
GetCellText gets the text content of a cell
func (*Table) GetColumnCount ¶
GetColumnCount returns the number of columns in the table
func (*Table) GetRowCount ¶
GetRowCount returns the number of rows in the table
type TblCell ¶
type TblCell struct {
XMLName xml.Name `xml:"tc"`
Props *TcPr `xml:"tcPr,omitempty"`
Content []Paragraph `xml:"p"`
}
TblCell represents a table cell
type TblGrid ¶
type TblGrid struct {
XMLName xml.Name `xml:"tblGrid"`
Cols []TblGridCol `xml:"gridCol"`
}
TblGrid represents table grid/columns
type TblGridCol ¶
TblGridCol represents a table column
type TblPr ¶
type TblPr struct {
XMLName xml.Name `xml:"tblPr"`
Style *TblStyle `xml:"tblStyle,omitempty"`
Width *TblWidth `xml:"tblW,omitempty"`
}
TblPr represents table properties
type TblRow ¶
type TblRow struct {
XMLName xml.Name `xml:"tr"`
Props *TrPr `xml:"trPr,omitempty"`
Cells []TblCell `xml:"tc"`
}
TblRow represents a table row
type TblWidth ¶
type TblWidth struct {
XMLName xml.Name `xml:"tblW"`
Type string `xml:"type,attr"`
W string `xml:"w,attr"`
}
TblWidth represents table width