Skip to content

Commit d490a0f

Browse files
authored
RichTextRun support set superscript and subscript by vertAlign attribute (qax-os#1252)
check vertical align enumeration, update set rich text docs and test
1 parent d383f0a commit d490a0f

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

cell.go

+23-5
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,10 @@ func newRpr(fnt *Font) *xlsxRPr {
848848
if fnt.Family != "" {
849849
rpr.RFont = &attrValString{Val: &fnt.Family}
850850
}
851-
if fnt.Size > 0.0 {
851+
if inStrSlice([]string{"baseline", "superscript", "subscript"}, fnt.VertAlign, true) != -1 {
852+
rpr.VertAlign = &attrValString{Val: &fnt.VertAlign}
853+
}
854+
if fnt.Size > 0 {
852855
rpr.Sz = &attrValFloat{Val: &fnt.Size}
853856
}
854857
if fnt.Color != "" {
@@ -895,7 +898,7 @@ func newRpr(fnt *Font) *xlsxRPr {
895898
// },
896899
// },
897900
// {
898-
// Text: " italic",
901+
// Text: "italic ",
899902
// Font: &excelize.Font{
900903
// Bold: true,
901904
// Color: "e83723",
@@ -926,19 +929,34 @@ func newRpr(fnt *Font) *xlsxRPr {
926929
// },
927930
// },
928931
// {
932+
// Text: " superscript",
933+
// Font: &excelize.Font{
934+
// Color: "dbc21f",
935+
// VertAlign: "superscript",
936+
// },
937+
// },
938+
// {
929939
// Text: " and ",
930940
// Font: &excelize.Font{
931-
// Size: 14,
932-
// Color: "ad23e8",
941+
// Size: 14,
942+
// Color: "ad23e8",
943+
// VertAlign: "baseline",
933944
// },
934945
// },
935946
// {
936-
// Text: "underline.",
947+
// Text: "underline",
937948
// Font: &excelize.Font{
938949
// Color: "23e833",
939950
// Underline: "single",
940951
// },
941952
// },
953+
// {
954+
// Text: " subscript.",
955+
// Font: &excelize.Font{
956+
// Color: "017505",
957+
// VertAlign: "subscript",
958+
// },
959+
// },
942960
// }); err != nil {
943961
// fmt.Println(err)
944962
// return

cell_test.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func TestSetCellRichText(t *testing.T) {
590590
},
591591
},
592592
{
593-
Text: "text with color and font-family,",
593+
Text: "text with color and font-family, ",
594594
Font: &Font{
595595
Bold: true,
596596
Color: "2354e8",
@@ -611,20 +611,35 @@ func TestSetCellRichText(t *testing.T) {
611611
Strike: true,
612612
},
613613
},
614+
{
615+
Text: " superscript",
616+
Font: &Font{
617+
Color: "dbc21f",
618+
VertAlign: "superscript",
619+
},
620+
},
614621
{
615622
Text: " and ",
616623
Font: &Font{
617-
Size: 14,
618-
Color: "ad23e8",
624+
Size: 14,
625+
Color: "ad23e8",
626+
VertAlign: "BASELINE",
619627
},
620628
},
621629
{
622-
Text: "underline.",
630+
Text: "underline",
623631
Font: &Font{
624632
Color: "23e833",
625633
Underline: "single",
626634
},
627635
},
636+
{
637+
Text: " subscript.",
638+
Font: &Font{
639+
Color: "017505",
640+
VertAlign: "subscript",
641+
},
642+
},
628643
}
629644
assert.NoError(t, f.SetCellRichText("Sheet1", "A1", richTextRun))
630645
assert.NoError(t, f.SetCellRichText("Sheet1", "A2", richTextRun))

xmlStyles.go

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ type Font struct {
341341
Size float64 `json:"size"`
342342
Strike bool `json:"strike"`
343343
Color string `json:"color"`
344+
VertAlign string `json:"vertAlign"`
344345
}
345346

346347
// Fill directly maps the fill settings of the cells.

0 commit comments

Comments
 (0)