| View previous topic :: View next topic |
| Author |
Message |
PsychoticBoredom Power User

Joined: 04 Nov 2005 Posts: 68 Location: Houston, Texas
|
Posted: Wed Apr 12, 2006 12:27 pm Post subject: change number format in cell via macro to one decimal place? |
|
|
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 |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Wed Apr 12, 2006 7:47 pm Post subject: |
|
|
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 |
|
 |
PsychoticBoredom Power User

Joined: 04 Nov 2005 Posts: 68 Location: Houston, Texas
|
Posted: Fri Apr 14, 2006 12:46 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|