123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- package excelutil
- import "github.com/xuri/excelize/v2"
- type style struct {
- file *excelize.File
- }
- func NewStyle(file *excelize.File) *style {
- return &style{
- file: file,
- }
- }
- func (s *style) NewBoldTitleStyleId() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 标题加粗
- Font: &excelize.Font{
- Bold: true,
- Color: "000000",
- },
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- // 单元格内容过多则自动换行
- WrapText: true,
- },
- })
- return styleID, err
- }
- func (s *style) NewBoldBorderTitleStyleId() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 标题加粗
- Font: &excelize.Font{
- Bold: true,
- Color: "000000",
- },
- // 设置边框
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- // 单元格内容过多则自动换行
- WrapText: true,
- },
- })
- return styleID, err
- }
- func (s *style) NewGreenBoldBorderTitleStyleId() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 标题加粗
- Font: &excelize.Font{
- Bold: true,
- Color: "FFFFFF",
- },
- // 设置边框
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- // 图案填充-绿色
- Fill: excelize.Fill{
- Pattern: 1,
- Type: "pattern",
- Color: []string{"2EA121"},
- },
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- // 单元格内容过多则自动换行
- WrapText: true,
- },
- })
- return styleID, err
- }
- func (s *style) NewYellowBoldBorderTitleStyleId() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 标题加粗
- Font: &excelize.Font{
- Bold: true,
- Color: "FFFFFF",
- },
- // 设置边框
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- // 图案填充-黄色
- Fill: excelize.Fill{
- Pattern: 1,
- Type: "pattern",
- Color: []string{"FFC60A"},
- },
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- // 单元格内容过多则自动换行
- WrapText: true,
- },
- })
- return styleID, err
- }
- func (s *style) NewDefaultValueStyleId() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- },
- })
- return styleID, err
- }
- func (s *style) NewDefaultValueStyleIdWithBorder() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 设置边框
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- },
- })
- return styleID, err
- }
- func (s *style) NewDefaultTimeStyleId() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- },
- NumFmt: 22,
- })
- return styleID, err
- }
- func (s *style) NewDefaultTimeStyleIdWithBorder() (int, error) {
- styleID, err := s.file.NewStyle(&excelize.Style{
- // 设置边框
- Border: []excelize.Border{
- {Type: "left", Color: "000000", Style: 1},
- {Type: "top", Color: "000000", Style: 1},
- {Type: "bottom", Color: "000000", Style: 1},
- {Type: "right", Color: "000000", Style: 1},
- },
- // 居中
- Alignment: &excelize.Alignment{
- // 水平对齐:
- Horizontal: "center",
- // 垂直对齐
- Vertical: "center",
- },
- NumFmt: 22,
- })
- return styleID, err
- }
|