|
|
|
@ -1896,7 +1896,7 @@ func (f *File) NewStyle(style string) (int, error) {
|
|
|
|
|
|
|
|
|
|
if fs.Font != nil {
|
|
|
|
|
s.Fonts.Count++
|
|
|
|
|
s.Fonts.Font = append(s.Fonts.Font, setFont(fs))
|
|
|
|
|
s.Fonts.Font = append(s.Fonts.Font, f.setFont(fs))
|
|
|
|
|
fontID = s.Fonts.Count - 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1932,7 +1932,7 @@ func (f *File) NewConditionalStyle(style string) (int, error) {
|
|
|
|
|
Border: setBorders(fs),
|
|
|
|
|
}
|
|
|
|
|
if fs.Font != nil {
|
|
|
|
|
dxf.Font = setFont(fs)
|
|
|
|
|
dxf.Font = f.setFont(fs)
|
|
|
|
|
}
|
|
|
|
|
dxfStr, _ := xml.Marshal(dxf)
|
|
|
|
|
if s.Dxfs == nil {
|
|
|
|
@ -1945,9 +1945,32 @@ func (f *File) NewConditionalStyle(style string) (int, error) {
|
|
|
|
|
return s.Dxfs.Count - 1, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetDefaultFont provides the default font name currently set in the workbook
|
|
|
|
|
// Documents generated by excelize start with Calibri
|
|
|
|
|
func (f *File) GetDefaultFont() string {
|
|
|
|
|
font := f.readDefaultFont()
|
|
|
|
|
return font.Name.Val
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetDefaultFont changes the default font in the workbook
|
|
|
|
|
func (f *File) SetDefaultFont(fontName string) {
|
|
|
|
|
font := f.readDefaultFont()
|
|
|
|
|
font.Name.Val = fontName
|
|
|
|
|
s := f.stylesReader()
|
|
|
|
|
s.Fonts.Font[0] = font
|
|
|
|
|
custom := true
|
|
|
|
|
s.CellStyles.CellStyle[0].CustomBuiltIn = &custom
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// readDefaultFont provides an unmarshalled font value
|
|
|
|
|
func (f *File) readDefaultFont() *xlsxFont {
|
|
|
|
|
s := f.stylesReader()
|
|
|
|
|
return s.Fonts.Font[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setFont provides a function to add font style by given cell format
|
|
|
|
|
// settings.
|
|
|
|
|
func setFont(formatStyle *formatStyle) *xlsxFont {
|
|
|
|
|
func (f *File) setFont(formatStyle *formatStyle) *xlsxFont {
|
|
|
|
|
fontUnderlineType := map[string]string{"single": "single", "double": "double"}
|
|
|
|
|
if formatStyle.Font.Size < 1 {
|
|
|
|
|
formatStyle.Font.Size = 11
|
|
|
|
@ -1955,7 +1978,7 @@ func setFont(formatStyle *formatStyle) *xlsxFont {
|
|
|
|
|
if formatStyle.Font.Color == "" {
|
|
|
|
|
formatStyle.Font.Color = "#000000"
|
|
|
|
|
}
|
|
|
|
|
f := xlsxFont{
|
|
|
|
|
fnt := xlsxFont{
|
|
|
|
|
B: formatStyle.Font.Bold,
|
|
|
|
|
I: formatStyle.Font.Italic,
|
|
|
|
|
Sz: &attrValInt{Val: formatStyle.Font.Size},
|
|
|
|
@ -1963,15 +1986,14 @@ func setFont(formatStyle *formatStyle) *xlsxFont {
|
|
|
|
|
Name: &attrValString{Val: formatStyle.Font.Family},
|
|
|
|
|
Family: &attrValInt{Val: 2},
|
|
|
|
|
}
|
|
|
|
|
if f.Name.Val == "" {
|
|
|
|
|
f.Name.Val = "Calibri"
|
|
|
|
|
f.Scheme = &attrValString{Val: "minor"}
|
|
|
|
|
if fnt.Name.Val == "" {
|
|
|
|
|
fnt.Name.Val = f.GetDefaultFont()
|
|
|
|
|
}
|
|
|
|
|
val, ok := fontUnderlineType[formatStyle.Font.Underline]
|
|
|
|
|
if ok {
|
|
|
|
|
f.U = &attrValString{Val: val}
|
|
|
|
|
fnt.U = &attrValString{Val: val}
|
|
|
|
|
}
|
|
|
|
|
return &f
|
|
|
|
|
return &fnt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setNumFmt provides a function to check if number format code in the range
|
|
|
|
|