41 lines
966 B
Go
41 lines
966 B
Go
package export
|
|
|
|
import "github.com/xuri/excelize/v2"
|
|
|
|
type Title struct {
|
|
// 标题名称
|
|
Name string
|
|
// 标题位置(列)
|
|
Location Location
|
|
// 标题合并列数(除开本身)
|
|
Colspan int
|
|
// 标题合并行数(除开本身)
|
|
Rowspan int
|
|
Style *excelize.Style
|
|
}
|
|
|
|
type Location struct {
|
|
X int
|
|
Y int
|
|
}
|
|
|
|
func (e *Exporter) SetGlobalTitleStyle(style *excelize.Style) {
|
|
e.GlobalTitleStyle = style
|
|
}
|
|
|
|
func (e *Exporter) SetTitle(sheet string) {
|
|
for _, title := range e.Titles {
|
|
start_col, end_col := e.CaculateCell(title.Location, title.Rowspan, title.Colspan)
|
|
e.xlsx.MergeCell(sheet, start_col, end_col)
|
|
e.xlsx.SetCellValue(sheet, start_col, title.Name)
|
|
if title.Style != nil {
|
|
style, _ := e.xlsx.NewStyle(title.Style)
|
|
e.xlsx.SetCellStyle(sheet, start_col, end_col, style)
|
|
} else if e.GlobalTitleStyle != nil {
|
|
style, _ := e.xlsx.NewStyle(e.GlobalTitleStyle)
|
|
e.xlsx.SetCellStyle(sheet, start_col, end_col, style)
|
|
|
|
}
|
|
}
|
|
}
|