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)
| 1385 | // } |
| 1386 | // } |
| 1387 | func (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 |