We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

Bold only for First word in the Paragraph

asked 2019-02-07 09:57:35 +0200

Nithin gravatar image

updated 2021-05-30 01:59:22 +0200

Alex Kemp gravatar image

Hello everyone,

is it possible to set the formatting of only the first word in a Paragraph to Bold. Use case is a simple dictionary formatting.

This would have been possible using the Drop Caps feature if the number of lines setting could be set to 1. This would also allow formatting initials. Here is a link explaining the difference between drop caps and Initials http://www.magazinedesigning.com/drop...

Is there any other way to do this?


edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2019-02-07 15:00:53 +0200

Lupp gravatar image

Any way? Not by ready-made means, I'm afraid, in specific not by settings implemented with the paragraph style concept as it is. You need to do it by "hard" assignment of an appropriate characzter style.

You can define a named pragraph style (may otherwise be identical with Default e.g.) and a named character style you want to apply to the initial word s of paragraphs haveing the mentioned style assigned.

Then you only need a little "macro" for the task. Resorting to "macros" always comes with disadvantages, however.

See the example FirstWordAsInitial.


Sub setCharStyleFirstWord(Optional pDoc As Object, Optional pText As Object, _
Optional pParaStyleN As String, Optional pCharStyleN As String)
REM This way to use a missing optional parameter as a local variable is 
REM not supported in very old versions of LibO and in AOO.
If IsMissing(pDoc) Then pDoc = ThisComponent
If NOT pDoc.supportsService("com.sun.star.text.TextDocument") Then Exit Sub
If IsMissing(pText) Then pText = ThisComponent.Text
If IsMissing(pParaStyleN) Then pParaStyleN = "paraInitialWord"
If IsMissing(pCharStyleN) Then pCharStyleN = "charInitialWord"
oldSel = pDoc.CurrentSelection
cur = pText.createTextCursorByRange(pText.Start)
REM Now the WORKING code:  

Do While pText.compareRegionEnds(cur, pText.End)>0
 If cur.ParaStyleName=pParaStyleN Then
  cur.CharStyleName = pCharStyleN
 End If

REM Done!
End Sub
edit flag offensive delete link more

answered 2019-02-14 11:58:19 +0200

Nithin gravatar image

Hello Lupp, Thanks a lot for the solution. This exactly what i was looking for. Thanks again for investing so much time and effort. I guess i will also create a enhancement request for the same.

edit flag offensive delete link more


Mike Kaganski gravatar imageMike Kaganski ( 2019-02-14 12:06:53 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-02-07 09:57:35 +0200

Seen: 929 times

Last updated: Feb 14 '19