[Issue] Uppercase to lowercase with capital letter

Discuss the word processor
Post Reply
carra
Posts: 8
Joined: Sun Jun 01, 2008 9:07 pm

[Issue] Uppercase to lowercase with capital letter

Post by carra »

 Edit: Hagar: split the thread from: [Solved] Format uppercase to lowercase with capital letter related to Calc. 
Is there a way to accomplish the same task (i.e. decapitalize uppercase words to lowercase with capital letter) in Writer?
Last edited by Hagar Delest on Sat Jun 28, 2008 12:02 pm, edited 1 time in total.
Reason: Tagged thread as Issue (link to a bug report).
OOo 3.0.X on Ms Windows XP + Ubuntu
TerryE
Volunteer
Posts: 1402
Joined: Sat Oct 06, 2007 10:13 pm
Location: UK

Re: format uppercase to lowercase with capital letter

Post by TerryE »

You can easily drop all letters in a selected region to lowercase by Format->Change Case->Lowercase, but changing just the first letter is a little more complex. You need to read up on regular expression searches. Do a find all on \<[A-Z] and this will highlight all first letters. You can now lowercase these as before.
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.
ERR
Posts: 24
Joined: Wed Nov 28, 2007 7:02 pm

Re: format uppercase to lowercase with capital letter

Post by ERR »

It would great if it had a third option

Format
__>Change Case
_____>UPPERCASE,
_____>lowercase,
_____>First Letter Uppercase.
TerryE
Volunteer
Posts: 1402
Joined: Sat Oct 06, 2007 10:13 pm
Location: UK

[Solved] Format uppercase to lowercase with capital letter

Post by TerryE »

First Letter Uppercase / Title Case. Vote for http://qa.openoffice.org/issues/show_bug.cgi?id=1601 :-)
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.
User avatar
TheGurkha
Volunteer
Posts: 6482
Joined: Thu Mar 13, 2008 12:13 pm
Location: North Wales, UK.

Re: [Issue] Uppercase to lowercase with capital letter

Post by TheGurkha »

This is what I use.

This Macro:

Code: Select all

Sub CaseToggle
' CaseToggleMk3 phb 20070828
' Should preserve formatting and bookmarks in Writer
' Should work on text within a table in Writer (but not on whole cells)
' Should work on multiple words
' Does not handle non-contiguous text selection
   dim document,dispatcher,vcursor,oText,alpha,omega,ThisSeln,oBookmark As Object
   dim seln,nextword,nextbit as string
   dim loops,posn,nSelCount as integer
   dim ctogbmpv(0) as new com.sun.star.beans.PropertyValue
   On Error GoTo ExitPoint ' In case selection is not text
   nSelCount = thiscomponent.getCurrentSelection().getCount()
   if nSelCount>1 then
      msgbox ("There seems to be more than one piece of text selected." & _
      chr(10) & "Try making one selection.",0,"Case Conversion")
      goto ExitPoint
   endif
   loops=0
   document=ThisComponent.CurrentController.Frame
   dispatcher=createUnoService("com.sun.star.frame.DispatchHelper")
   vcursor=ThisComponent.currentcontroller.getViewCursor()
   ctogbmpv(0).Name="Bookmark"
   ctogbmpv(0).Value="ctogbm"
   dispatcher.executeDispatch(document, ".uno:DeleteBookmark", "", 0, ctogbmpv())
   dispatcher.executeDispatch(document, ".uno:InsertBookmark", "", 0, ctogbmpv())
GetSeln: ' Much here is taken from Andrew Brown and Andrew Pitonyak
   oText=vcursor.getText()
   alpha=vcursor.getStart()
   omega=vcursor.getEnd()
   ThisSeln=oText.createTextCursorByRange(alpha)
   ThisSeln.goToRange(omega,TRUE)
   seln=ThisSeln.getString()
   if seln<>"" then ' There is a selection - go and change case
      goto ChgCase
   endif ' make a selection to change
   dispatcher.executeDispatch(document, ".uno:GoToNextWord", "", 0, Array())
   dispatcher.executeDispatch(document, ".uno:WordLeftSel", "", 0, Array())
   loops=loops+1
   if loops=2 then goto FinishOff ' in case we failed to find any text to select
   goto GetSeln
ChgCase: 'Check case of seln and alter accordingly
    if seln=ucase(seln) then 'seln is already UPPER - set to lower
      dispatcher.executeDispatch(document, ".uno:ChangeCaseToLower", "", 0, Array())
       goto SetToTitle
    endif
   if seln=lcase(seln) then 'seln is already lower - set to Title
       goto SetToTitle
    endif 'seln is probably mixed case - set to UPPER
       dispatcher.executeDispatch(document, ".uno:ChangeCaseToLower", "", 0, Array())
       goto SetToTitle
SetToTitle:
      vcursor.collapsetoStart()     
      posn=0
      do while posn<len(seln)
         loops=0
         nextbit="1"
         do while nextbit=lcase(nextbit) and loops<2
            vcursor.goRight(1,TRUE)
            dispatcher.executeDispatch(document, ".uno:ChangeCaseToUpper", "", 0, Array())
            alpha=vcursor.getStart()
            omega=vcursor.getEnd()
            ThisSeln=oText.createTextCursorByRange(alpha)
            ThisSeln.goToRange(omega,TRUE)
            nextbit=ThisSeln.getString()
            loops=loops+1
         loop
            if instr(nextbit," ")>0 or instr(nextbit,chr(10))>0 then
               vcursor.goLeft(1,TRUE) ' To avoid problems due to punctuation marks
            endif
         dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())
         alpha=vcursor.getStart()
         omega=vcursor.getEnd()
         ThisSeln=oText.createTextCursorByRange(alpha)
         ThisSeln.goToRange(omega,TRUE)
         nextword=ThisSeln.getString()
         posn=posn + len(nextword)
         vcursor.collapsetoEnd()
      loop
FinishOff: 'set vcursor back to the original position
   oBookmark=ThisComponent.getBookmarks().getByName("ctogbm")
   ThisComponent.getCurrentController().select(oBookmark)
   dispatcher.executeDispatch(document, ".uno:DeleteBookmark", "", 0, ctogbmpv())
ExitPoint:
end Sub 
And I assigned it to Shift-F3 and added it to the Format menu as well. Sorted.

Here are Bhikkhu Pesala's tips for adding macros to menus and buttons: Assigning a Macro to a Button
Attachments
menu.png
menu.png (6.41 KiB) Viewed 89784 times
Ubuntu 14.10 Utopic Unicorn, LibreOffice Version: 4.3.3.2
Gurkha Welfare Trust
carra
Posts: 8
Joined: Sun Jun 01, 2008 9:07 pm

Re: [Issue] Uppercase to lowercase with capital letter

Post by carra »

TheGurkha,
where should I place the code of your macro in Openoffice, to make it work?
Thank you.
OOo 3.0.X on Ms Windows XP + Ubuntu
User avatar
Hagar Delest
Moderator
Posts: 32667
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Issue] Uppercase to lowercase with capital letter

Post by Hagar Delest »

LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
HowardMcCay
Posts: 2
Joined: Fri Mar 12, 2010 1:37 am

Re: [Issue] Uppercase to lowercase with capital letter

Post by HowardMcCay »

I am new to Open Office. I am very pleasantly surprised at its many built in features. I still can hardly believe that so vast and robust a project is provided to the community for free. Open Office is certainly a giant labor of love.

On the subject of initial capitals for each word in a selection, I am shocked and surprised at the omission of initial capitals as a built in feature. I find it especially hard to believe there is no built in capitalization feature after reading the help documentation. The help documentation seems to indicate that it is possible to capitalize text without writing a macro. Is it really necessary to write a macro to capitalize text? It seems to me that if you go to all the trouble to write your macro in macro code, one could write the same logic in C++ code and improve the Open Office Writer product. I wonder if any one is investigating the possibility of using the logic in your macro to write a built in function for the Writer.

I reproduce below an issue report that I guess I was chewed out for submitting. I still do not know my way around the Open Office organization.
________________________________________________________________________________________________________________________

Issue 111980

start:

Query | Reports
Issue 111980
Issue #: 111980 Platform: Unknown Reporter: howardmccay (howardmccay)
Component: Word processor OS: Windows Vista
Subcomponent: editing Version: OOO320m9 CC: None defined
Status: CLOSED Priority: P3
Resolution: INVALID Issue type: DEFECT
Target milestone: ---
Assigned to: writerneedsconfirm (writerneedsconfirm)
QA Contact: issues@sw
URL:
* Summary: How to capitalize the first letter of each word in text?
Status whiteboard:
Keywords:
Attachments:
Issue 111980 depends on: Show dependency tree
Issue 111980 blocks:
Votes for issue 111980: Vote for this issue

View issue activity | Format for printing | Format as XML
Description: Opened: Tue Jun 1 05:03:00 +0000 2010 Sort by: Oldest first | Newest first

The help documentation (F1) in the word processor version OOO320m12 reads:
_________________________________________________________________________

Changing the Case of Text
You can change the case of text, format text with small capitals, or capitalize
the first letter of each word in a selection
.

When you apply a formatting to your text by Format - Character, the text stays
the same, it is only displayed in another way. On the other hand, when you
choose Format - Change Case, the text is permanently changed.

To Capitalize Text
1.Select the text that you want to capitalize.
2.Do one of the following:
To Change Text to Lowercase
1.Select the text that you want to change to lowercase.
2.Do one of the following:
_________________________________________________________________________

This documentation seems to indicate that it is possible to get the word
processor to capitalize the first letter of each word in selected text,
but fails to indicate how to do this.
The menu Format>Change Case has two options: Uppercase and Lowercase.
There is no initial letter capitalize option.
Microsoft word rotates among all lowercase, all uppercase, and initial capitals
in the selected text when you press shift-F3. Can Open Office Writer do this?

------- Additional comments from mru Tue Jun 1 07:16:29 +0000 2010 -------

This is not a support forum, please refer to mailing list “users@openoffice.org
or http://support.openoffice.org.

------- Additional comments from mru Tue Jun 1 07:16:54 +0000 2010 -------

Closed.
OpenOffice.org 3.2.0 OOO320m12 (Build:9483) on Windows Vista Home Premium 2007 service pack 1
User avatar
RGB
Posts: 1456
Joined: Mon Oct 08, 2007 1:34 am

Re: [Issue] Uppercase to lowercase with capital letter

Post by RGB »

3.3 will introduce more options:
Sentence case
lowercase
UPPERCASE
Capitalize Every Word
tOGGLE cASE
There are two types of people: those who believe that there are two types of people and those who do not.

openSUSE Leap with KDE Plasma / LibreOffice
Taolin
Posts: 2
Joined: Thu Jul 08, 2010 6:06 am

Re: [Issue] Uppercase to lowercase with capital letter

Post by Taolin »

Dear Gurkha,
While not as elegant as yours, here is a macro I built for this problem. It works on subsequent words after the first, also and I stuck it on a tool bar under the "A arrow to B arrow to A" icon.

Code: Select all

sub CaseCorrect
rem ---Starting at cursor, it sets a Capital, then the rest of the word lower. -
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Count"
args4(0).Value = 1
args4(1).Name = "Select"
args4(1).Value = true 
 dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args4())
 dispatcher.executeDispatch(document, ".uno:ChangeCaseToUpper", "", 0, Array())
 dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array())
 dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())
 dispatcher.executeDispatch(document, ".uno:ChangeCaseToLower", "", 0, Array())
 dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array())

end sub
OpenOffice 3.2.1 on Suse 11.2/KDE 4.4.4
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: [Issue] Uppercase to lowercase with capital letter

Post by floris v »

RGB wrote:3.3 will introduce more options:
Sentence case
lowercase
UPPERCASE
Capitalize Every Word
tOGGLE cASE
I don't see them any more in release candidate 5. What's happened?
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
Hagar Delest
Moderator
Posts: 32667
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Issue] Uppercase to lowercase with capital letter

Post by Hagar Delest »

I've it on xubuntu 10.10 with 3.3RC5 just installed:
Case.png
Case.png (14.58 KiB) Viewed 81966 times
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: [Issue] Uppercase to lowercase with capital letter

Post by floris v »

Commented in the issue discussion.
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: [Issue] Uppercase to lowercase with capital letter

Post by floris v »

Addendum: the new options are available in Calc but not in Writer.
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
floris v
Volunteer
Posts: 4431
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: [Issue] Uppercase to lowercase with capital letter

Post by floris v »

Addendum: after installing the new language pack for Dutch the new options suddenly popped up (the installation damaged the user profile, I couldn't get a proper list of languages in the Options dialog box anymore, so I made a new one).
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
pincopallino
Posts: 1
Joined: Wed Jan 19, 2011 1:03 pm

Re: [Issue] Uppercase to lowercase with capital letter

Post by pincopallino »

hello to everybody,
I modyfied the code to achieve this:
UPPER case->lower case->Title case
(in previous version it converted always in Titlecase)
thanks to the original author,
hope this helps,
regards

Code: Select all

REM  *****  BASIC  *****

Sub CaseToggle
' CaseToggleMk3 phb 20070828
' Should preserve formatting and bookmarks in Writer
' Should work on text within a table in Writer (but not on whole cells)
' Should work on multiple words
' Does not handle non-contiguous text selection
   dim document,dispatcher,vcursor,oText,alpha,omega,ThisSeln,oBookmark As Object
   dim seln,nextword,nextbit as string
   dim loops,posn,nSelCount as integer
   dim ctogbmpv(0) as new com.sun.star.beans.PropertyValue
   On Error GoTo ExitPoint ' In case selection is not text
   nSelCount = thiscomponent.getCurrentSelection().getCount()
   if nSelCount>1 then
      msgbox ("There seems to be more than one piece of text selected." & _
      chr(10) & "Try making one selection.",0,"Case Conversion")
      goto ExitPoint
   endif
   loops=0
   document=ThisComponent.CurrentController.Frame
   dispatcher=createUnoService("com.sun.star.frame.DispatchHelper")
   vcursor=ThisComponent.currentcontroller.getViewCursor()
   ctogbmpv(0).Name="Bookmark"
   ctogbmpv(0).Value="ctogbm"
   dispatcher.executeDispatch(document, ".uno:DeleteBookmark", "", 0, ctogbmpv())
   dispatcher.executeDispatch(document, ".uno:InsertBookmark", "", 0, ctogbmpv())
GetSeln: ' Much here is taken from Andrew Brown and Andrew Pitonyak
   oText=vcursor.getText()
   alpha=vcursor.getStart()
   omega=vcursor.getEnd()
   ThisSeln=oText.createTextCursorByRange(alpha)
   ThisSeln.goToRange(omega,TRUE)
   seln=ThisSeln.getString()
   if seln<>"" then ' There is a selection - go and change case
      goto ChgCase
   endif ' make a selection to change
   dispatcher.executeDispatch(document, ".uno:GoToNextWord", "", 0, Array())
   dispatcher.executeDispatch(document, ".uno:WordLeftSel", "", 0, Array())
   loops=loops+1
   if loops=2 then goto FinishOff ' in case we failed to find any text to select
   goto GetSeln
ChgCase: 'Check case of seln and alter accordingly
    if seln=ucase(seln) then 'seln is already UPPER - set to lower
      dispatcher.executeDispatch(document, ".uno:ChangeCaseToLower", "", 0, Array())
       goto FinishOff
    endif
   if seln=lcase(seln) then 'seln is already lower - set to Title
          goto SetToTitle
    endif 'seln is probably mixed case - set to UPPER
       dispatcher.executeDispatch(document, ".uno:ChangeCaseToUpper", "", 0, Array())
       goto FinishOff

SetToTitle:
      vcursor.collapsetoStart()     
      posn=0
      do while posn<len(seln)
         loops=0
         nextbit="1"
         do while nextbit=lcase(nextbit) and loops<2
            vcursor.goRight(1,TRUE)
            dispatcher.executeDispatch(document, ".uno:ChangeCaseToUpper", "", 0, Array())
            alpha=vcursor.getStart()
            omega=vcursor.getEnd()
            ThisSeln=oText.createTextCursorByRange(alpha)
            ThisSeln.goToRange(omega,TRUE)
            nextbit=ThisSeln.getString()
            loops=loops+1
         loop
            if instr(nextbit," ")>0 or instr(nextbit,chr(10))>0 then
               vcursor.goLeft(1,TRUE) ' To avoid problems due to punctuation marks
            endif
         dispatcher.executeDispatch(document, ".uno:WordRightSel", "", 0, Array())
         alpha=vcursor.getStart()
         omega=vcursor.getEnd()
         ThisSeln=oText.createTextCursorByRange(alpha)
         ThisSeln.goToRange(omega,TRUE)
         nextword=ThisSeln.getString()
         posn=posn + len(nextword)
         vcursor.collapsetoEnd()
      loop
FinishOff: 'set vcursor back to the original position
   oBookmark=ThisComponent.getBookmarks().getByName("ctogbm")
   ThisComponent.getCurrentController().select(oBookmark)
   dispatcher.executeDispatch(document, ".uno:DeleteBookmark", "", 0, ctogbmpv())
ExitPoint:
end Sub
OpenOffice 3.1 on Ubuntu 9.10
Post Reply