[Basic, Python] Reporting all number format locales

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

[Basic, Python] Reporting all number format locales

Post by Villeroy »

2019-03-27: Added an easy to use Python installer.
The following code dumps info about all number format locales into a new spreadsheet. In addition it formats the first 1024 columns of each row (until column IV) in the "General" number format of the respective locale so you can test the input patterns and default appearance of dates and times etc.

Code: Select all

Sub printAllLocalesToNewSpreadSheet()
Dim oDoc, oSheet, i18n, oInfo, a(), b(),i%, oItem, nf&, nfs&

oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc","_default",0,Array())
oSheet = oDoc.getSheets().getByIndex(0)
nfs = com.sun.star.i18n.NumberFormatIndex.NUMBER_STANDARD

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()

nf = oDoc.NumberFormats.getStandardIndex(a(i))
oSheet.getCellRangeByPosition(0, i+1, 255, i+1).NumberFormat = nf
next
oSheet.getCellRangeByPosition(0, 0, cCols, uBound(r())).setDataArray(r())
End Sub

Function getLocaleString(oL)
dim s$
s = oL.Language
if len(oL.Country) then
	s = s &"-"& oL.Country
	if len(oL.Variant) then s = s &"-"& oL.Variant
End If
getLocaleString = s
End Function
The Python version of the above StarBasic code can be viewed and installed with the attached text document.
Attachments
reportLocales.odt
Python code in a Writer document with StarBasic installer.
(24.47 KiB) Downloaded 157 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply