The following snippet copies contents of a cell to the same cell and preserves fromatting (font color, effects etc.).
Sub Main
Set oRange = ThisComponent.CurrentSelection
For i = 0 To oRange.Rows.getCount() - 1
For j = 0 To oRange.Columns.getCount() - 1
Set oCell = oRange.getCellByPosition( j, i )
oCell.String = oCell.String
Next
Next
End Sub
However if you concatenate it with another string, for example:
oCell.String = oCell.String + " test appendix"
All text in the cell loses it’s formatting:
Is there any way to edit that text and preserve any formatting? Or is there a way to read formatting from it and recreate it afterwards? I may be remiss on my understanding of formatting in libreoffice in general.