[Solved] Cell String with bold or italic parts

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

[Solved] Cell String with bold or italic parts

Post by VBandOoffice »

Hi all,
I've got a problem again: I need to format a cell string partly bold (or italic). If I put the string manually to the cell, this is simple: Mark a part of the string and click to bold or Format/Character/ and so on.
But how to build this kind of string by an Basic Macro? I tried to use XRay to an already formatted string - but failed to find a solution.

Thanks in advance,
VBandOoffice
Last edited by VBandOoffice on Wed Oct 31, 2018 8:56 am, edited 2 times in total.
LibreOffice 7.5, Windows 10, VB.net 2019, C#
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Cell String with bold or cursive parts

Post by FJCC »

Here is an example of making the first 4 characters in cell A1 bold.

Code: Select all

  oSheets = ThisComponent.getSheets()
  oSheet1 = oSheets.getByName("Sheet1")
  oCellRangeByName = oSheet1.getCellRangeByName("A1")
  
  oText = oCellRangeByName.getText()
  oCurs = oText.createTextCursor()
  oCurs.gotoStart(FALSE)
  oCurs.goRight(4, True)
  oCurs.CharWeight = 150
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
VBandOoffice
Posts: 33
Joined: Tue Jul 31, 2018 10:11 am

Re: [solved] Cell String with bold or cursive parts

Post by VBandOoffice »

Thank you very much FJCC!

by the way, if you want to switch to italic you have to change CharPosture to 2 (normal=0)

Best regards,
VBandOoffice
LibreOffice 7.5, Windows 10, VB.net 2019, C#
Post Reply