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 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 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) 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) RemoveStyle(styleID string)
- func (sm *StyleManager) StyleExists(styleID string) bool
- type StyleName
- type StyleType
- type Styles
- type TableCellProperties
- type TableProperties
- type TableRowProperties
- 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 ParagraphProperties ¶
type ParagraphProperties struct {
XMLName xml.Name `xml:"w:pPr"`
Spacing *Spacing `xml:"w:spacing,omitempty"`
Justification *Justification `xml:"w:jc,omitempty"`
Indentation *Indentation `xml:"w:ind,omitempty"`
KeepNext *KeepNext `xml:"w:keepNext,omitempty"`
KeepLines *KeepLines `xml:"w:keepLines,omitempty"`
PageBreak *PageBreak `xml:"w:pageBreakBefore,omitempty"`
OutlineLevel *OutlineLevel `xml:"w:outlineLvl,omitempty"`
}
ParagraphProperties 段落样式属性
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"`
Bold *Bold `xml:"w:b,omitempty"`
Italic *Italic `xml:"w:i,omitempty"`
Underline *Underline `xml:"w:u,omitempty"`
Strike *Strike `xml:"w:strike,omitempty"`
FontSize *FontSize `xml:"w:sz,omitempty"`
Color *Color `xml:"w:color,omitempty"`
FontFamily *FontFamily `xml:"w:rFonts,omitempty"`
Highlight *Highlight `xml:"w:highlight,omitempty"`
}
RunProperties 字符样式属性
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) 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) 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 ¶
TableProperties 表格样式属性
type TableRowProperties ¶
TableRowProperties 表格行样式属性