Documentation
¶
Overview ¶
Package style 样式应用API
Package style 预定义样式常量 ¶
Package style 提供Word文档样式管理功能
Index ¶
- Constants
- func GetPredefinedStyleNames() map[string]string
- type BasedOn
- type Bold
- type Color
- type FontFamily
- type FontSize
- type Highlight
- type Indentation
- type Italic
- type Justification
- type KeepLines
- type KeepNext
- type Next
- type OutlineLevel
- type PageBreak
- type ParagraphBorder
- type ParagraphBorderLine
- type ParagraphProperties
- type QuickParagraphConfig
- type QuickRunConfig
- type QuickStyleAPI
- func (api *QuickStyleAPI) CreateQuickStyle(config QuickStyleConfig) (*Style, error)
- func (api *QuickStyleAPI) GetAllStylesInfo() []*StyleInfo
- func (api *QuickStyleAPI) GetCharacterStylesInfo() []*StyleInfo
- func (api *QuickStyleAPI) GetHeadingStylesInfo() []*StyleInfo
- func (api *QuickStyleAPI) GetParagraphStylesInfo() []*StyleInfo
- func (api *QuickStyleAPI) GetStyleInfo(styleID string) (*StyleInfo, error)
- type QuickStyleConfig
- type RunProperties
- type Shading
- type Spacing
- type Strike
- type Style
- type StyleApplicator
- type StyleConfig
- type StyleInfo
- type StyleManager
- func (sm *StyleManager) AddStyle(style *Style)
- func (sm *StyleManager) ApplyStyleToXML(styleID string) (map[string]interface{}, error)
- func (sm *StyleManager) Clone() *StyleManager
- func (sm *StyleManager) CreateCustomStyle(styleID, name string, styleType StyleType, basedOn string) *Style
- func (sm *StyleManager) GetAllStyles() []*Style
- func (sm *StyleManager) GetHeadingStyles() []*Style
- func (sm *StyleManager) GetStyle(styleID string) *Style
- func (sm *StyleManager) GetStyleWithInheritance(styleID string) *Style
- func (sm *StyleManager) GetStylesByType(styleType StyleType) []*Style
- func (sm *StyleManager) LoadStylesFromDocument(xmlData []byte) error
- func (sm *StyleManager) MergeStylesFromXML(xmlData []byte) error
- func (sm *StyleManager) ParseStylesFromXML(xmlData []byte) error
- func (sm *StyleManager) RemoveStyle(styleID string)
- func (sm *StyleManager) StyleExists(styleID string) bool
- type StyleName
- type StyleType
- type Styles
- type TableCellProperties
- type TableProperties
- type TableRowProperties
- type TblBorder
- type TblBorders
- type TblCellMargin
- type TblCellSpace
- type TblIndent
- type Underline
Constants ¶
const ( // StyleNormal 普通文本样式 StyleNormal = "Normal" // 标题样式 StyleHeading1 = "Heading1" StyleHeading2 = "Heading2" StyleHeading3 = "Heading3" StyleHeading4 = "Heading4" StyleHeading5 = "Heading5" StyleHeading6 = "Heading6" StyleHeading7 = "Heading7" StyleHeading8 = "Heading8" StyleHeading9 = "Heading9" // 文档标题样式 StyleTitle = "Title" // 文档标题 StyleSubtitle = "Subtitle" // 副标题 // 字符样式 StyleEmphasis = "Emphasis" // 强调(斜体) StyleStrong = "Strong" // 加粗 StyleCodeChar = "CodeChar" // 代码字符 // 段落样式 StyleQuote = "Quote" // 引用样式 StyleListParagraph = "ListParagraph" // 列表段落 StyleCodeBlock = "CodeBlock" // 代码块 )
预定义样式ID常量
Variables ¶
This section is empty.
Functions ¶
func GetPredefinedStyleNames ¶
GetPredefinedStyleNames 获取所有预定义样式名称映射
Types ¶
type FontFamily ¶
type Indentation ¶
type Justification ¶
type OutlineLevel ¶
type ParagraphBorder ¶ added in v1.3.9
type ParagraphBorder struct {
XMLName xml.Name `xml:"w:pBdr"`
Top *ParagraphBorderLine `xml:"w:top,omitempty"`
Left *ParagraphBorderLine `xml:"w:left,omitempty"`
Bottom *ParagraphBorderLine `xml:"w:bottom,omitempty"`
Right *ParagraphBorderLine `xml:"w:right,omitempty"`
}
ParagraphBorder 段落边框
type ParagraphBorderLine ¶ added in v1.3.9
type ParagraphBorderLine struct {
XMLName xml.Name `xml:""`
Val string `xml:"w:val,attr"`
Color string `xml:"w:color,attr"`
Sz string `xml:"w:sz,attr"`
Space string `xml:"w:space,attr"`
}
ParagraphBorderLine 段落边框线
type ParagraphProperties ¶
type ParagraphProperties struct {
XMLName xml.Name `xml:"w:pPr"`
KeepNext *KeepNext `xml:"w:keepNext,omitempty"`
KeepLines *KeepLines `xml:"w:keepLines,omitempty"`
PageBreak *PageBreak `xml:"w:pageBreakBefore,omitempty"`
ParagraphBorder *ParagraphBorder `xml:"w:pBdr,omitempty"`
Shading *Shading `xml:"w:shd,omitempty"`
Spacing *Spacing `xml:"w:spacing,omitempty"`
Indentation *Indentation `xml:"w:ind,omitempty"`
Justification *Justification `xml:"w:jc,omitempty"`
OutlineLevel *OutlineLevel `xml:"w:outlineLvl,omitempty"`
}
ParagraphProperties 段落样式属性 注意:字段顺序必须符合OpenXML标准
type QuickParagraphConfig ¶
type QuickParagraphConfig struct {
Alignment string `json:"alignment,omitempty"` // left, center, right, justify
LineSpacing float64 `json:"lineSpacing,omitempty"` // 行间距倍数
SpaceBefore int `json:"spaceBefore,omitempty"` // 段前间距(磅)
SpaceAfter int `json:"spaceAfter,omitempty"` // 段后间距(磅)
FirstLineIndent int `json:"firstLineIndent,omitempty"` // 首行缩进(磅)
LeftIndent int `json:"leftIndent,omitempty"` // 左缩进(磅)
RightIndent int `json:"rightIndent,omitempty"` // 右缩进(磅)
}
QuickParagraphConfig 快速段落配置
type QuickRunConfig ¶
type QuickRunConfig struct {
FontName string `json:"fontName,omitempty"` // 字体名称
FontSize int `json:"fontSize,omitempty"` // 字体大小(磅)
FontColor string `json:"fontColor,omitempty"` // 字体颜色(十六进制)
Bold bool `json:"bold,omitempty"` // 粗体
Italic bool `json:"italic,omitempty"` // 斜体
Underline bool `json:"underline,omitempty"` // 下划线
Strike bool `json:"strike,omitempty"` // 删除线
Highlight string `json:"highlight,omitempty"` // 高亮颜色
}
QuickRunConfig 快速字符配置
type QuickStyleAPI ¶
type QuickStyleAPI struct {
// contains filtered or unexported fields
}
QuickStyleAPI 快速样式应用API
func NewQuickStyleAPI ¶
func NewQuickStyleAPI(styleManager *StyleManager) *QuickStyleAPI
NewQuickStyleAPI 创建快速样式API
func (*QuickStyleAPI) CreateQuickStyle ¶
func (api *QuickStyleAPI) CreateQuickStyle(config QuickStyleConfig) (*Style, error)
CreateQuickStyle 快速创建自定义样式
func (*QuickStyleAPI) GetAllStylesInfo ¶
func (api *QuickStyleAPI) GetAllStylesInfo() []*StyleInfo
GetAllStylesInfo 获取所有样式信息
func (*QuickStyleAPI) GetCharacterStylesInfo ¶
func (api *QuickStyleAPI) GetCharacterStylesInfo() []*StyleInfo
GetCharacterStylesInfo 获取字符样式信息
func (*QuickStyleAPI) GetHeadingStylesInfo ¶
func (api *QuickStyleAPI) GetHeadingStylesInfo() []*StyleInfo
GetHeadingStylesInfo 获取所有标题样式信息
func (*QuickStyleAPI) GetParagraphStylesInfo ¶
func (api *QuickStyleAPI) GetParagraphStylesInfo() []*StyleInfo
GetParagraphStylesInfo 获取段落样式信息
func (*QuickStyleAPI) GetStyleInfo ¶
func (api *QuickStyleAPI) GetStyleInfo(styleID string) (*StyleInfo, error)
GetStyleInfo 获取样式信息(用于UI显示)
type QuickStyleConfig ¶
type QuickStyleConfig struct {
ID string `json:"id"`
Name string `json:"name"`
Type StyleType `json:"type"`
BasedOn string `json:"basedOn,omitempty"`
ParagraphConfig *QuickParagraphConfig `json:"paragraphConfig,omitempty"`
RunConfig *QuickRunConfig `json:"runConfig,omitempty"`
}
QuickStyleConfig 快速样式配置
type RunProperties ¶
type RunProperties struct {
XMLName xml.Name `xml:"w:rPr"`
FontFamily *FontFamily `xml:"w:rFonts,omitempty"`
Bold *Bold `xml:"w:b,omitempty"`
Italic *Italic `xml:"w:i,omitempty"`
Underline *Underline `xml:"w:u,omitempty"`
Strike *Strike `xml:"w:strike,omitempty"`
Color *Color `xml:"w:color,omitempty"`
FontSize *FontSize `xml:"w:sz,omitempty"`
Highlight *Highlight `xml:"w:highlight,omitempty"`
}
RunProperties 字符样式属性 注意:字段顺序必须符合OpenXML标准,w:rFonts必须在w:color之前
type Shading ¶ added in v1.3.9
type Shading struct {
XMLName xml.Name `xml:"w:shd"`
Fill string `xml:"w:fill,attr"`
Val string `xml:"w:val,attr,omitempty"`
}
Shading 阴影/填充色
type Spacing ¶
type Spacing struct {
XMLName xml.Name `xml:"w:spacing"`
Before string `xml:"w:before,attr,omitempty"`
After string `xml:"w:after,attr,omitempty"`
Line string `xml:"w:line,attr,omitempty"`
LineRule string `xml:"w:lineRule,attr,omitempty"`
}
基础样式元素定义
type Style ¶
type Style struct {
XMLName xml.Name `xml:"w:style"`
Type string `xml:"w:type,attr"`
StyleID string `xml:"w:styleId,attr"`
Name *StyleName `xml:"w:name,omitempty"`
BasedOn *BasedOn `xml:"w:basedOn,omitempty"`
Next *Next `xml:"w:next,omitempty"`
Default bool `xml:"w:default,attr,omitempty"`
CustomStyle bool `xml:"w:customStyle,attr,omitempty"`
ParagraphPr *ParagraphProperties `xml:"w:pPr,omitempty"`
RunPr *RunProperties `xml:"w:rPr,omitempty"`
TablePr *TableProperties `xml:"w:tblPr,omitempty"`
TableRowPr *TableRowProperties `xml:"w:trPr,omitempty"`
TableCellPr *TableCellProperties `xml:"w:tcPr,omitempty"`
}
Style 样式定义
type StyleApplicator ¶
type StyleApplicator interface {
ApplyStyle(styleID string) error
ApplyHeadingStyle(level int) error
ApplyTitleStyle() error
ApplySubtitleStyle() error
ApplyQuoteStyle() error
ApplyCodeBlockStyle() error
ApplyListParagraphStyle() error
ApplyNormalStyle() error
}
StyleApplicator 样式应用器接口
type StyleConfig ¶
StyleConfig 样式配置帮助结构
func GetPredefinedStyleConfigs ¶
func GetPredefinedStyleConfigs() []StyleConfig
GetPredefinedStyleConfigs 获取所有预定义样式配置
type StyleInfo ¶
type StyleInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Type StyleType `json:"type"`
Description string `json:"description"`
IsBuiltIn bool `json:"isBuiltIn"`
BasedOn string `json:"basedOn,omitempty"`
}
StyleInfo 样式信息结构
type StyleManager ¶
type StyleManager struct {
// contains filtered or unexported fields
}
StyleManager 样式管理器
func (*StyleManager) ApplyStyleToXML ¶
func (sm *StyleManager) ApplyStyleToXML(styleID string) (map[string]interface{}, error)
ApplyStyleToXML 将样式应用到XML结构(为文档集成做准备)
func (*StyleManager) Clone ¶ added in v1.3.7
func (sm *StyleManager) Clone() *StyleManager
Clone 深拷贝样式管理器,用于模板渲染时避免样式冲突
func (*StyleManager) CreateCustomStyle ¶
func (sm *StyleManager) CreateCustomStyle(styleID, name string, styleType StyleType, basedOn string) *Style
CreateCustomStyle 创建自定义样式
func (*StyleManager) GetAllStyles ¶
func (sm *StyleManager) GetAllStyles() []*Style
GetAllStyles 获取所有样式
func (*StyleManager) GetHeadingStyles ¶
func (sm *StyleManager) GetHeadingStyles() []*Style
GetHeadingStyles 获取所有标题样式
func (*StyleManager) GetStyle ¶
func (sm *StyleManager) GetStyle(styleID string) *Style
GetStyle 获取指定ID的样式
func (*StyleManager) GetStyleWithInheritance ¶
func (sm *StyleManager) GetStyleWithInheritance(styleID string) *Style
GetStyleWithInheritance 获取具有继承属性的样式 如果样式基于其他样式,会合并父样式的属性
func (*StyleManager) GetStylesByType ¶
func (sm *StyleManager) GetStylesByType(styleType StyleType) []*Style
GetStylesByType 按类型获取样式
func (*StyleManager) LoadStylesFromDocument ¶ added in v1.3.6
func (sm *StyleManager) LoadStylesFromDocument(xmlData []byte) error
LoadStylesFromDocument 从现有文档加载样式,优先保留原有样式设置
func (*StyleManager) MergeStylesFromXML ¶ added in v1.3.6
func (sm *StyleManager) MergeStylesFromXML(xmlData []byte) error
MergeStylesFromXML 从XML数据合并样式(保留现有样式,只添加新的)
func (*StyleManager) ParseStylesFromXML ¶ added in v1.3.6
func (sm *StyleManager) ParseStylesFromXML(xmlData []byte) error
ParseStylesFromXML 从XML数据解析样式
func (*StyleManager) RemoveStyle ¶
func (sm *StyleManager) RemoveStyle(styleID string)
RemoveStyle 移除样式
func (*StyleManager) StyleExists ¶
func (sm *StyleManager) StyleExists(styleID string) bool
StyleExists 检查样式是否存在
type Styles ¶
type Styles struct {
XMLName xml.Name `xml:"w:styles"`
Xmlns string `xml:"xmlns:w,attr"`
Styles []Style `xml:"w:style"`
}
Styles 样式集合
type TableCellProperties ¶
TableCellProperties 表格单元格样式属性
type TableProperties ¶
type TableProperties struct {
XMLName xml.Name `xml:"w:tblPr"`
TblInd *TblIndent `xml:"w:tblInd,omitempty"` // 表格缩进
TblBorders *TblBorders `xml:"w:tblBorders,omitempty"` // 表格边框
TblCellMar *TblCellMargin `xml:"w:tblCellMar,omitempty"` // 表格单元格边距
}
TableProperties 表格样式属性
type TableRowProperties ¶
TableRowProperties 表格行样式属性
type TblBorder ¶ added in v1.3.7
type TblBorder struct {
Val string `xml:"w:val,attr"`
Sz string `xml:"w:sz,attr"`
Space string `xml:"w:space,attr"`
Color string `xml:"w:color,attr"`
}
TblBorder 表格边框定义
type TblBorders ¶ added in v1.3.7
type TblBorders struct {
XMLName xml.Name `xml:"w:tblBorders"`
Top *TblBorder `xml:"w:top,omitempty"`
Left *TblBorder `xml:"w:left,omitempty"`
Bottom *TblBorder `xml:"w:bottom,omitempty"`
Right *TblBorder `xml:"w:right,omitempty"`
InsideH *TblBorder `xml:"w:insideH,omitempty"`
InsideV *TblBorder `xml:"w:insideV,omitempty"`
}
TblBorders 表格边框
type TblCellMargin ¶ added in v1.3.7
type TblCellMargin struct {
XMLName xml.Name `xml:"w:tblCellMar"`
Top *TblCellSpace `xml:"w:top,omitempty"`
Left *TblCellSpace `xml:"w:left,omitempty"`
Bottom *TblCellSpace `xml:"w:bottom,omitempty"`
Right *TblCellSpace `xml:"w:right,omitempty"`
}
TblCellMargin 表格单元格边距
type TblCellSpace ¶ added in v1.3.7
TblCellSpace 表格单元格空间