先生成一个样式,保存样式的id:style

样式设置参考:NewStyle

  1. style, err := f.NewStyle(`{
  2. "font":{//字体样式
  3. "bold":true,
  4. "color":"0ff",
  5. "size": 16
  6. },
  7. "fill":{
  8. "type":"pattern",//纯色填充
  9. "color": ["f0c"],
  10. "pattern": 1
  11. },
  12. "border": [//边框
  13. {
  14. "type": "left",
  15. "color": "FF0000",
  16. "style": 3
  17. },
  18. {
  19. "type": "top",
  20. "color": "FF0000",
  21. "style": 4
  22. },
  23. {
  24. "type": "bottom",
  25. "color": "FF0000",
  26. "style": 5
  27. },
  28. {
  29. "type": "right",
  30. "color": "FF0000",
  31. "style": 6
  32. }
  33. ]
  34. }`)

应用样式

  1. func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error

其中的参数hcell,vcell,指的是左上角和右下角的单元格格地址,如果只设置一个单元格,就写成一样的

  1. f.SetCellStyle("Sheet2", "A1", "D3", style)