设置样式
-
新建样式
func (f *File) NewStyle(style interface{}) (int, error)
通过给定的样式格式 JSON 或结构体的指针创建样式并返回样式索引。请注意,颜色需要使用 RGB 色域代码表示。
-
设置样式
func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error
-
样式结构体包含的设置项
type Style struct {
Border []Border `json:"border"`
Fill Fill `json:"fill"`
Font *Font `json:"font"`
Alignment *Alignment `json:"alignment"`
Protection *Protection `json:"protection"`
NumFmt int `json:"number_format"`
DecimalPlaces int `json:"decimal_places"`
CustomNumFmt *string `json:"custom_number_format"`
Lang string `json:"lang"`
NegRed bool `json:"negred"`
}
- 边框
type Border struct {
Type string `json:"type"` // top bottom left right diagonalDown diagonalUp
Color string `json:"color"` // 常用的颜色字符串 以及 十六进制的颜色编 red #F8F8F8
Style int `json:"style"` // 见下表 样式可以去文档上看
}
索引 | 线条样式 | 线宽 |
---|---|---|
0 | 无 | 0 |
1 | 连续线 | 1 |
2 | 连续线 | 2 |
3 | 短线 | 1 |
4 | 点线 | 1 |
5 | 连续线 | 3 |
6 | 双线 | 3 |
7 | 连续线 | 0 |
8 | 短线 | 2 |
9 | 短线与点间隔线 | 1 |
10 | 短线与点间隔线 | 2 |
11 | 短线与两个点一组重复线 | 1 |
12 | 短线与两个点一组重复线 | 2 |
13 | 斜线与点线 | 2 |
- 填充
type Fill struct {
Type string `json:"type"` // gradient pattern
Pattern int `json:"pattern"`
Color []string `json:"color"`
Shading int `json:"shading"`
}
填充有两种类型 即 Type 有两种选择 gradient -> 渐变色 pattern -> 填充图案
当Type是 gradient 时,Shading 可以选择 0-5 分别代表标横向(每种颜色横向分布),纵向,纵向 对角向上 对角向下 有外向内 由内向外;此时的Color 切片中的颜色可以有多个,Pattern 可以忽略
当Type是 pattern 时,Pattern 可选 0-18 其中 1是实体填充 ;Color 切片中只要一种;Shading可以不填
只有上述两种组合,其他的组合都不显示填充颜色
- 字体
type Font struct {
Bold bool `json:"bold"` // 是否加粗
Italic bool `json:"italic"` // 是否倾斜
Underline string `json:"underline"` // single double
Family string `json:"family"` // 字体样式
Size float64 `json:"size"` // 字体大小
Strike bool `json:"strike"` // 删除线
Color string `json:"color"` // 字体颜色
}
注意字体是指针类型的
- 保护
type Protection