1. package main
    2. import (
    3. "fmt"
    4. "github.com/xuri/excelize/v2"
    5. )
    6. func main() {
    7. f := excelize.NewFile()
    8. if err := f.SetRowHeight("Sheet1", 1, 35); err != nil {
    9. fmt.Println(err)
    10. return
    11. }
    12. if err := f.SetColWidth("Sheet1", "A", "A", 44); err != nil {
    13. fmt.Println(err)
    14. return
    15. }
    16. if err := f.SetCellRichText("Sheet1", "A1", []excelize.RichTextRun{
    17. {
    18. Text: "bold",
    19. Font: &excelize.Font{
    20. Bold: true,
    21. Color: "2354e8",
    22. Family: "Times New Roman",
    23. },
    24. },
    25. {
    26. Text: " and ",
    27. Font: &excelize.Font{
    28. Family: "Times New Roman",
    29. },
    30. },
    31. {
    32. Text: "italic ",
    33. Font: &excelize.Font{
    34. Italic: true,
    35. Family: "Times New Roman",
    36. },
    37. },
    38. {
    39. Text: "text with color and font-family,",
    40. Font: &excelize.Font{
    41. Bold: true,
    42. Color: "2354e8",
    43. Family: "Times New Roman",
    44. },
    45. },
    46. {
    47. Text: "\r\nlarge text with ",
    48. Font: &excelize.Font{
    49. Size: 14,
    50. Color: "ad23e8",
    51. },
    52. },
    53. {
    54. Text: "strike",
    55. Font: &excelize.Font{
    56. Color: "e89923",
    57. Strike: true,
    58. },
    59. },
    60. {
    61. Text: " superscript",
    62. Font: &excelize.Font{
    63. Color: "dbc21f",
    64. VertAlign: "superscript",
    65. },
    66. },
    67. {
    68. Text: " and ",
    69. Font: &excelize.Font{
    70. VertAlign: "baseline",
    71. },
    72. },
    73. {
    74. Text: "underline",
    75. Font: &excelize.Font{
    76. Color: "23e833",
    77. Underline: "single",
    78. },
    79. },
    80. {
    81. Text: " subscript.",
    82. Font: &excelize.Font{
    83. Color: "017505",
    84. VertAlign: "subscript",
    85. },
    86. },
    87. }); err != nil {
    88. fmt.Println(err)
    89. return
    90. }
    91. style, err := f.NewStyle(&excelize.Style{
    92. Alignment: &excelize.Alignment{
    93. WrapText: true,
    94. },
    95. })
    96. if err != nil {
    97. fmt.Println(err)
    98. return
    99. }
    100. if err := f.SetCellStyle("Sheet1", "A1", "A1", style); err != nil {
    101. fmt.Println(err)
    102. return
    103. }
    104. if err := f.SaveAs("Book1.xlsx"); err != nil {
    105. fmt.Println(err)