2013/3/10 Johnny Rosenberg <gurus.knugum@gmail.com>:
2013/3/10 Alex Thurgood <alex.thurgood@gmail.com>:
Le 09/03/2013 21:52, Johnny Rosenberg a écrit :
Hi Johnny,
http://api.libreoffice.org/docs/common/ref/com/sun/star/i18n/LocaleDataItem.html#decimalSeparator
Thanks! That looks like what I was looking for!
Now I only need to figure out how to use it…
But don't worry, I will.
Johnny Rosenberg
Alex
I did some more searching after a couple of failed experiments, and I
found this code at
http://www.oooforum.org/forum/viewtopic.phtml?t=121837:
REM - - - CODE STARTS HERE - - -
Sub printAllLocalesToNewSpreadSheet()
Dim oDoc, oSheet, i18n, oInfo, a(), b(),i%, oItem
i18n = createUnoService("com.sun.star.i18n.LocaleData")
a() = i18n.getAllInstalledLocaleNames()
dim r(uBound(a()) +1)
Const cCols = 7
r(0) = Array("Locale","Language","Country","Decimal","Date","Time","1000","List")
For i = 0 to uBound(a())
oInfo = i18n.getLanguageCountryInfo(a(i))
oItem = i18n.getLocaleItem(a(i))
b() = Array( _
getLocaleString(a(i)), _
oInfo.LanguageDefaultName, _
oInfo.CountryDefaultName, _
oItem.decimalSeparator, _
oItem.dateSeparator, _
oItem.timeSeparator, _
oItem.thousandSeparator, _
oItem.listSeparator _
)
r(i +1) = b()
next
oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc","_default",0,Array())
oSheet = oDoc.getSheets().getByIndex(0)
oSheet.getCellRangeByPosition(0, 0, cCols, uBound(r())).setDataArray(r())
End Sub
REM - - - CODE ENDS HERE - - -
However, it seems like some code is not complete. There is no
getLocaleString and there are a few more issues with it, so I edited
it a bit:
✓ I wrote a new getLocaleString function.
✓ I eliminated the need for the cCols variable, making the whole thing
work a little bit more ”automatically”.
✓ I removed the lines that create a new spreadsheet, printing on the
existing one instead. This is just a test thing anyway.
✓ I ”Johnnyfied” the code slightly, which isn't necessarily a good
thing… For example the Dim statements: For some of them, I couldn't
decide whether to use Object or Variant, please correct me if
necessary.
Here's my version anyway, and it works:
REM - - - CODE STARTS HERE - - -
Sub printAllLocalesToSpreadSheet()
Dim oSheet As Object
Dim i18n As Object, oInfo As Object, oItem As Object
Dim a() As Variant, b() As Variant
Dim i As Integer
i18n=createUnoService("com.sun.star.i18n.LocaleData")
a()=i18n.getAllInstalledLocaleNames()
Dim r(uBound(a())+1)
r(0)=Array("Locale","Language","Country","Decimal","Date","Time","1000","List")
For i=0 to uBound(a())
oInfo=i18n.getLanguageCountryInfo(a(i))
oItem=i18n.getLocaleItem(a(i))
b()=Array( _
getLocaleString(a(i)), _
oInfo.LanguageDefaultName, _
oInfo.CountryDefaultName, _
oItem.decimalSeparator, _
oItem.dateSeparator, _
oItem.timeSeparator, _
oItem.thousandSeparator, _
oItem.listSeparator _
)
r(i+1)=b()
Next
oSheet=ThisComponent.getSheets().getByIndex(0)
oSheet.getCellRangeByPosition(0,0,uBound(r(0)),uBound(r())).setDataArray(r())
End Sub
Function getLocaleString(x As Variant) As String
Dim sString As String
sString=x.Language & "_" & x.Country
If x.Variant="" Then
getLocaleString=sString
Else
getLocaleString=getLocaleString & "(" & x.Variant & ")"
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.