OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

change number format in cell via macro to one decimal place?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
PsychoticBoredom
Power User
Power User


Joined: 04 Nov 2005
Posts: 68
Location: Houston, Texas

PostPosted: Wed Apr 12, 2006 12:27 pm    Post subject: change number format in cell via macro to one decimal place? Reply with quote

Hi,

If I have a value in cell A1 of 9, and I want to use macro code to make sure it displays as 9.0, what do I do? How can I set numberFormat or numberFormatValue for that once cell to show one place after the decimal? I want to do this in a Star Basic macro, not via right clicking and using cell format.
_________________
"Think like a genius. Act like a fool."
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Wed Apr 12, 2006 7:47 pm    Post subject: Reply with quote

This will set the number format of the cell/s selected. This is for the format you mention. To use for another format, change the value of sFormat. I used information in Andrew Pitonyak's document.
Code:
Sub NumFormat

Dim aLocale as new com.sun.star.lang.Locale, oDoc as Object, _
oSelect as Object, sFormat as String, vNumFormat

'aLocale.Language = "en" : aLocale.Country = "AU" 'optional
oDoc = ThisComponent : oSelect = oDoc.CurrentSelection : sFormat = "0.0"
vNumFormat = oDoc.getNumberFormats().queryKey( sFormat, aLocale, TRUE)
If ( vNumFormat = -1 ) Then
vNumFormat = oDoc.getNumberFormats().addNew ( sFormat, aLocale )
End If
oSelect.NumberFormat = vNumFormat

End Sub
Back to top
View user's profile Send private message
PsychoticBoredom
Power User
Power User


Joined: 04 Nov 2005
Posts: 68
Location: Houston, Texas

PostPosted: Fri Apr 14, 2006 12:46 pm    Post subject: Reply with quote

Thanks for the suggestion. I tried it out, but it didn't work in my case. After playing around a bit, what finally did work was to select the cells and format them to show once place after the decimal like this:

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value="$CV$20:$CW$21"
' for some reason using #.0 worked
dispatcher.executeDispatch(document, ".uno:GoToCell", "", #.0, args1())
_________________
"Think like a genius. Act like a fool."
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group