Skip to content

Commit

Permalink
This closes qax-os#1213, fix get incorrect rich text value caused by …
Browse files Browse the repository at this point in the history
…missing cell type checking
  • Loading branch information
xuri committed Jul 11, 2023
1 parent 2b0ff4e commit ec500fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cell.go
Expand Up @@ -764,7 +764,7 @@ func (f *File) GetCellRichText(sheet, cell string) (runs []RichTextRun, err erro
return
}
siIdx, err := strconv.Atoi(cellData.V)
if nil != err {
if err != nil || cellData.T != "s" {
return
}
sst := f.sharedStringsReader()
Expand All @@ -776,7 +776,7 @@ func (f *File) GetCellRichText(sheet, cell string) (runs []RichTextRun, err erro
run := RichTextRun{
Text: v.T.Val,
}
if nil != v.RPr {
if v.RPr != nil {
font := Font{Underline: "none"}
font.Bold = v.RPr.B != nil
font.Italic = v.RPr.I != nil
Expand All @@ -793,7 +793,7 @@ func (f *File) GetCellRichText(sheet, cell string) (runs []RichTextRun, err erro
font.Size = *v.RPr.Sz.Val
}
font.Strike = v.RPr.Strike != nil
if nil != v.RPr.Color {
if v.RPr.Color != nil {
font.Color = strings.TrimPrefix(v.RPr.Color.RGB, "FF")
}
run.Font = &font
Expand Down
7 changes: 6 additions & 1 deletion cell_test.go
Expand Up @@ -502,8 +502,13 @@ func TestGetCellRichText(t *testing.T) {
},
}
assert.NoError(t, f.SetCellRichText("Sheet1", "A1", runsSource))
assert.NoError(t, f.SetCellValue("Sheet1", "A2", false))

runs, err := f.GetCellRichText("Sheet1", "A1")
runs, err := f.GetCellRichText("Sheet1", "A2")
assert.NoError(t, err)
assert.Equal(t, []RichTextRun(nil), runs)

runs, err = f.GetCellRichText("Sheet1", "A1")
assert.NoError(t, err)

assert.Equal(t, runsSource[0].Text, runs[0].Text)
Expand Down

0 comments on commit ec500fc

Please sign in to comment.