forked from p30928647/excelize
RichTextRun support set superscript and subscript by vertAlign attribute (#1252)
check vertical align enumeration, update set rich text docs and test
This commit is contained in:
parent
d383f0ae6e
commit
d490a0f86f
30
cell.go
30
cell.go
|
@ -848,7 +848,10 @@ func newRpr(fnt *Font) *xlsxRPr {
|
|||
if fnt.Family != "" {
|
||||
rpr.RFont = &attrValString{Val: &fnt.Family}
|
||||
}
|
||||
if fnt.Size > 0.0 {
|
||||
if inStrSlice([]string{"baseline", "superscript", "subscript"}, fnt.VertAlign, true) != -1 {
|
||||
rpr.VertAlign = &attrValString{Val: &fnt.VertAlign}
|
||||
}
|
||||
if fnt.Size > 0 {
|
||||
rpr.Sz = &attrValFloat{Val: &fnt.Size}
|
||||
}
|
||||
if fnt.Color != "" {
|
||||
|
@ -895,7 +898,7 @@ func newRpr(fnt *Font) *xlsxRPr {
|
|||
// },
|
||||
// },
|
||||
// {
|
||||
// Text: " italic",
|
||||
// Text: "italic ",
|
||||
// Font: &excelize.Font{
|
||||
// Bold: true,
|
||||
// Color: "e83723",
|
||||
|
@ -926,19 +929,34 @@ func newRpr(fnt *Font) *xlsxRPr {
|
|||
// },
|
||||
// },
|
||||
// {
|
||||
// Text: " and ",
|
||||
// Text: " superscript",
|
||||
// Font: &excelize.Font{
|
||||
// Size: 14,
|
||||
// Color: "ad23e8",
|
||||
// Color: "dbc21f",
|
||||
// VertAlign: "superscript",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Text: "underline.",
|
||||
// Text: " and ",
|
||||
// Font: &excelize.Font{
|
||||
// Size: 14,
|
||||
// Color: "ad23e8",
|
||||
// VertAlign: "baseline",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Text: "underline",
|
||||
// Font: &excelize.Font{
|
||||
// Color: "23e833",
|
||||
// Underline: "single",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Text: " subscript.",
|
||||
// Font: &excelize.Font{
|
||||
// Color: "017505",
|
||||
// VertAlign: "subscript",
|
||||
// },
|
||||
// },
|
||||
// }); err != nil {
|
||||
// fmt.Println(err)
|
||||
// return
|
||||
|
|
25
cell_test.go
25
cell_test.go
|
@ -590,7 +590,7 @@ func TestSetCellRichText(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
Text: "text with color and font-family,",
|
||||
Text: "text with color and font-family, ",
|
||||
Font: &Font{
|
||||
Bold: true,
|
||||
Color: "2354e8",
|
||||
|
@ -612,19 +612,34 @@ func TestSetCellRichText(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
Text: " and ",
|
||||
Text: " superscript",
|
||||
Font: &Font{
|
||||
Size: 14,
|
||||
Color: "ad23e8",
|
||||
Color: "dbc21f",
|
||||
VertAlign: "superscript",
|
||||
},
|
||||
},
|
||||
{
|
||||
Text: "underline.",
|
||||
Text: " and ",
|
||||
Font: &Font{
|
||||
Size: 14,
|
||||
Color: "ad23e8",
|
||||
VertAlign: "BASELINE",
|
||||
},
|
||||
},
|
||||
{
|
||||
Text: "underline",
|
||||
Font: &Font{
|
||||
Color: "23e833",
|
||||
Underline: "single",
|
||||
},
|
||||
},
|
||||
{
|
||||
Text: " subscript.",
|
||||
Font: &Font{
|
||||
Color: "017505",
|
||||
VertAlign: "subscript",
|
||||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(t, f.SetCellRichText("Sheet1", "A1", richTextRun))
|
||||
assert.NoError(t, f.SetCellRichText("Sheet1", "A2", richTextRun))
|
||||
|
|
|
@ -341,6 +341,7 @@ type Font struct {
|
|||
Size float64 `json:"size"`
|
||||
Strike bool `json:"strike"`
|
||||
Color string `json:"color"`
|
||||
VertAlign string `json:"vertAlign"`
|
||||
}
|
||||
|
||||
// Fill directly maps the fill settings of the cells.
|
||||
|
|
Loading…
Reference in New Issue