style.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package xlsx
  2. import "strconv"
  3. // Style is a high level structure intended to provide user access to
  4. // the contents of Style within an XLSX file.
  5. type Style struct {
  6. Border Border
  7. Fill Fill
  8. Font Font
  9. }
  10. func NewStyle() *Style {
  11. return &Style{}
  12. }
  13. func (style *Style) makeXLSXStyleElements() (xFont xlsxFont, xFill xlsxFill, xBorder xlsxBorder, xCellStyleXf xlsxXf, xCellXf xlsxXf) {
  14. xFont = xlsxFont{}
  15. xFill = xlsxFill{}
  16. xBorder = xlsxBorder{}
  17. xCellStyleXf = xlsxXf{}
  18. xCellXf = xlsxXf{}
  19. xFont.Sz.Val = strconv.Itoa(style.Font.Size)
  20. xFont.Name.Val = style.Font.Name
  21. xFont.Family.Val = strconv.Itoa(style.Font.Family)
  22. xFont.Charset.Val = strconv.Itoa(style.Font.Charset)
  23. xPatternFill := xlsxPatternFill{}
  24. xPatternFill.PatternType = style.Fill.PatternType
  25. xPatternFill.FgColor.RGB = style.Fill.FgColor
  26. xPatternFill.BgColor.RGB = style.Fill.BgColor
  27. xFill.PatternFill = xPatternFill
  28. xBorder.Left = xlsxLine{Style: style.Border.Left}
  29. xBorder.Right = xlsxLine{Style: style.Border.Right}
  30. xBorder.Top = xlsxLine{Style: style.Border.Top}
  31. xBorder.Bottom = xlsxLine{Style: style.Border.Bottom}
  32. return
  33. }
  34. // Border is a high level structure intended to provide user access to
  35. // the contents of Border Style within an Sheet.
  36. type Border struct {
  37. Left string
  38. Right string
  39. Top string
  40. Bottom string
  41. }
  42. func NewBorder(left, right, top, bottom string) *Border {
  43. return &Border{Left: left, Right: right, Top: top, Bottom: bottom}
  44. }
  45. // Fill is a high level structure intended to provide user access to
  46. // the contents of background and foreground color index within an Sheet.
  47. type Fill struct {
  48. PatternType string
  49. BgColor string
  50. FgColor string
  51. }
  52. func NewFill(patternType, fgColor, bgColor string) *Fill {
  53. return &Fill{PatternType: patternType, FgColor: fgColor, BgColor: bgColor}
  54. }
  55. type Font struct {
  56. Size int
  57. Name string
  58. Family int
  59. Charset int
  60. }
  61. func NewFont(size int, name string) *Font {
  62. return &Font{Size: size, Name: name}
  63. }