MCPcopy
hub / github.com/qax-os/excelize / SetCellRichText

Method SetCellRichText

cell.go:1387–1420  ·  view source on GitHub ↗

SetCellRichText provides a function to set cell with rich text by given worksheet name, cell reference and rich text runs. For example, set rich text on the A1 cell of the worksheet named Sheet1: package main import ( "fmt" "github.com/xuri/excelize/v2" ) func main() { f := ex

(sheet, cell string, runs []RichTextRun)

Source from the content-addressed store, hash-verified

1385// }
1386// }
1387func (f *File) SetCellRichText(sheet, cell string, runs []RichTextRun) error {
1388 ws, err := f.workSheetReader(sheet)
1389 if err != nil {
1390 return err
1391 }
1392 c, col, row, err := ws.prepareCell(cell)
1393 if err != nil {
1394 return err
1395 }
1396 if err := f.sharedStringsLoader(); err != nil {
1397 return err
1398 }
1399 c.S = ws.prepareCellStyle(col, row, c.S)
1400 si := xlsxSI{}
1401 sst, err := f.sharedStringsReader()
1402 if err != nil {
1403 return err
1404 }
1405 if si.R, err = setRichText(runs); err != nil {
1406 return err
1407 }
1408 f.clearCalcCache()
1409 for idx, strItem := range sst.SI {
1410 if reflect.DeepEqual(strItem, si) {
1411 c.T, c.V = "s", strconv.Itoa(idx)
1412 return err
1413 }
1414 }
1415 sst.SI = append(sst.SI, si)
1416 sst.Count++
1417 sst.UniqueCount++
1418 c.T, c.V = "s", strconv.Itoa(len(sst.SI)-1)
1419 return err
1420}
1421
1422// SetSheetRow writes an array to row by given worksheet name, starting
1423// cell reference and a pointer to array type 'slice'. This function is

Callers 4

TestCalcCellValueCacheFunction · 0.95
TestGetCellRichTextFunction · 0.95
TestSetCellRichTextFunction · 0.95
TestSharedStringsErrorFunction · 0.80

Calls 7

workSheetReaderMethod · 0.95
sharedStringsLoaderMethod · 0.95
sharedStringsReaderMethod · 0.95
clearCalcCacheMethod · 0.95
setRichTextFunction · 0.85
prepareCellMethod · 0.80
prepareCellStyleMethod · 0.80

Tested by 4

TestCalcCellValueCacheFunction · 0.76
TestGetCellRichTextFunction · 0.76
TestSetCellRichTextFunction · 0.76
TestSharedStringsErrorFunction · 0.64