Documentation
¶
Index ¶
- func NewTemplateError(op string, err error) error
- func PreprocessTemplate(content string, data map[string]any) (string, error)
- type ChartData
- type ChartSeries
- type Metadata
- type PageSetup
- type Template
- func (t *Template) AddWatermark(text string) error
- func (t *Template) Apply(data map[string]any) error
- func (t *Template) Cleanup() error
- func (t *Template) Close() error
- func (t *Template) DetectCharts() ([]string, error)
- func (t *Template) GetChartCount() int
- func (t *Template) HTMLToOOXML(htmlContent string) (string, error)
- func (t *Template) HasCharts() bool
- func (t *Template) IncludeFooter(footerPath string) error
- func (t *Template) IncludeHeader(headerPath string) error
- func (t *Template) MergeDocuments(placeholders map[string]string) error
- func (t *Template) ReplaceChartData(chartName string, data ChartData) error
- func (t *Template) ReplaceText(placeholder, text string) error
- func (t *Template) Save(path string) error
- func (t *Template) SetContent(placeholder, htmlContent string) error
- func (t *Template) SetMetadata(meta Metadata) error
- func (t *Template) SetPageSetup(setup PageSetup) error
- func (t *Template) SetReadOnly(readOnly bool) error
- type TemplateError
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTemplateError ¶ added in v0.0.5
NewTemplateError creates a new template error with context
Types ¶
type ChartData ¶ added in v0.0.5
type ChartData struct {
Categories []string
Series []ChartSeries
}
ChartData represents data for a chart
type ChartSeries ¶ added in v0.0.5
ChartSeries represents a data series in a chart
type Metadata ¶ added in v0.0.5
type Metadata struct {
Title string
Subject string
Author string
Keywords string
Description string
Category string
}
Metadata represents document metadata properties
type PageSetup ¶ added in v0.0.5
type PageSetup struct {
PageWidth int // in twips (1/1440 inch)
PageHeight int
MarginTop int
MarginBottom int
MarginLeft int
MarginRight int
Orientation string // "portrait" or "landscape"
}
PageSetup represents page setup options
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template represents a DOCX document template that can be manipulated by replacing placeholders with HTML or plain text content.
func Open ¶
Open reads a DOCX file from the given path and prepares a Template for manipulation. It loads all document parts into memory for processing.
func (*Template) AddWatermark ¶ added in v0.0.5
AddWatermark adds a text watermark to the document This is a simplified implementation
func (*Template) Apply ¶
Apply replaces multiple placeholders in the document using a map. Keys are placeholder names (without braces), and values can be any type that can be stringified (string, int, float, bool, etc.). If a value is a string, it's processed as HTML (SetContent). For other types, it's processed as plain text.
This method also processes template directives like {#if} and {#items} loops before applying regular placeholders.
func (*Template) Cleanup ¶ added in v0.0.4
Cleanup removes any remaining placeholders from the document
func (*Template) Close ¶
Close releases the underlying ZIP file reader resources. It should be called when the template is no longer needed.
func (*Template) DetectCharts ¶ added in v0.0.5
DetectCharts finds all charts in the document
func (*Template) GetChartCount ¶ added in v0.0.5
GetChartCount returns the number of charts in the document
func (*Template) IncludeFooter ¶ added in v0.0.5
IncludeFooter includes a footer from an external DOCX file This is a simplified implementation
func (*Template) IncludeHeader ¶ added in v0.0.5
IncludeHeader includes a header from an external DOCX file This is a simplified implementation
func (*Template) MergeDocuments ¶ added in v0.0.5
MergeDocuments merges content from another DOCX file at a placeholder location Syntax: {@include:filename.docx}
func (*Template) ReplaceChartData ¶ added in v0.0.5
ReplaceChartData replaces data in a chart This is a simplified implementation that demonstrates the concept
func (*Template) ReplaceText ¶
ReplaceText is a simpler function that just replaces text without HTML parsing
func (*Template) Save ¶
Save writes the modified document to the specified output path. It compresses all document parts back into a DOCX (ZIP) file.
func (*Template) SetContent ¶
SetContent replaces a placeholder in the document with HTML-formatted content. The placeholder should be provided without curly braces (e.g., "content" for {{content}}). Blocks like tables and lists will be inserted as native Word elements.
func (*Template) SetMetadata ¶ added in v0.0.5
SetMetadata sets document properties in core.xml
func (*Template) SetPageSetup ¶ added in v0.0.5
SetPageSetup configures page margins and size
func (*Template) SetReadOnly ¶ added in v0.0.5
SetReadOnly sets document protection to read-only This is a simplified implementation
type TemplateError ¶ added in v0.0.5
TemplateError wraps errors with context
func (*TemplateError) Error ¶ added in v0.0.5
func (e *TemplateError) Error() string
func (*TemplateError) Unwrap ¶ added in v0.0.5
func (e *TemplateError) Unwrap() error
type ValidationError ¶ added in v0.0.5
type ValidationError struct {
Message string
Location string // e.g., "placeholder", "loop", "conditional"
Details string
}
ValidationError represents a template validation error
func ValidatePlaceholders ¶ added in v0.0.5
func ValidatePlaceholders(content string) []ValidationError
ValidatePlaceholders checks if placeholders are properly formatted
func (*ValidationError) Error ¶ added in v0.0.5
func (e *ValidationError) Error() string