libreoffice, numeric cell format

281 views
Skip to first unread message

Paola Bruccoleri

unread,
Nov 6, 2020, 5:44:10 PM11/6/20
to harbou...@googlegroups.com
Hi
I am exporting some data to an .ods file using
WIN_OLECREATEOBJECT ("com.sun.star.ServiceManager")

I can't find how to specify the number of decimal places in a cell.
I found some code for NumberFormat but not all
....setPropertyValue ("NumberFormat", 36)
(for example for a date).

I do not need to format with $ but simply indicate the number of decimal places

Already grateful.

Klas Engwall

unread,
Nov 6, 2020, 6:41:08 PM11/6/20
to harbou...@googlegroups.com

Paola Bruccoleri

unread,
Nov 6, 2020, 6:59:32 PM11/6/20
to harbou...@googlegroups.com
Hi Klas
Yes, I just found it but I can't find the syntax to pass it to harbour :)


----- Mensaje original -----
De: "Klas Engwall" <har...@engwall.com>
Para: harbou...@googlegroups.com
Enviados: Viernes, 6 de Noviembre 2020 20:40:56
Asunto: Re: [harbour-users] libreoffice, numeric cell format
--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/1d7dac3f-62fe-3256-532b-be2ae8c20549%40engwall.com.

Paola Bruccoleri

unread,
Nov 6, 2020, 7:11:53 PM11/6/20
to harbou...@googlegroups.com

oLocalSettings:= oPrograma:createInstance("com.sun.star.lang.Locale")
oLocalSettings:language := "es"
oLocalSettings:country := "es"
oNumberFormats:= oHoja:numberFormats
lKey := oNumberFormats:queryKey("0,00", oLocalSettings, .t.)
If lKey = -1
lKey := oNumberFormats:addNew("0,00", oLocalSettings)
endif

error base/1005: LANGUAGE


----- Mensaje original -----
De: "Paola Bruccoleri" <pbruc...@adinet.com.uy>
Para: harbou...@googlegroups.com
Enviados: Viernes, 6 de Noviembre 2020 20:59:15
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/1679930309.3043307.1604707155686.JavaMail.zimbra%40vera.com.uy.

Marek Olszewski "MOL"

unread,
Nov 7, 2020, 1:46:15 AM11/7/20
to Harbour Users
I'm using this code for numbers with 2 decimal places and it works OK:
oSheet:getCellRangeByPosition(nCol, nRow, nCol, nRow):NumberFormat := 4

Klas Engwall

unread,
Nov 7, 2020, 6:58:12 AM11/7/20
to harbou...@googlegroups.com
Hi Paola,

> oLocalSettings:= oPrograma:createInstance("com.sun.star.lang.Locale")
> oLocalSettings:language := "es"
> oLocalSettings:country := "es"
> oNumberFormats:= oHoja:numberFormats
> lKey := oNumberFormats:queryKey("0,00", oLocalSettings, .t.)
> If lKey = -1
> lKey := oNumberFormats:addNew("0,00", oLocalSettings)
> endif
>
> error base/1005: LANGUAGE

Is it the second line above that crashes? What valtype() is
oLocalSettings at that point? I get a feeling it is NIL rather than an
object.

And what is oPrograma? Is it the desktop or the workbook? It looks like
oHoja is the workbook, so try that instead of oPrograma to get the locale.

I use a slightly different approach:
oLocale := oWorkBook:getPropertyValue( 'CharLocale' )

The different objects retrieved with createInstance() are always
confusing in LibreOffice/OpenOffice :-)

Regards,
Klas

Paola Bruccoleri

unread,
Nov 7, 2020, 7:22:53 AM11/7/20
to harbou...@googlegroups.com
Hi Marek
It works perfect
Where did you find that code 4? I've been looking everywhere ...
Perhaps there are others such as for example to be 3 decimal places, etc.

Thanks a lot!


De: "Marek Olszewski \"MOL\"" <m...@pro.onet.pl>
Para: "Harbour Users" <harbou...@googlegroups.com>
Enviados: Sábado, 7 de Noviembre 2020 3:46:15

Paola Bruccoleri

unread,
Nov 7, 2020, 7:40:19 AM11/7/20
to harbou...@googlegroups.com
Hi Klas

oPrograma := WIN_OLECREATEOBJECT("com.sun.star.ServiceManager")
oPlanilla := oDesktop:loadComponentFromURL("private:factory/scalc", "_blank", 0, {})
oHoja := oPlanilla:getSheets:getByIndex(0)

Although Marek already suggested a change to me and it worked, I want to try this another.

Now with this modification:

oLocalSettings:= oPlanilla:getPropertyValue ('CharLocale')
oLocalSettings:language := "es"
oLocalSettings:country := "es"
oNumberFormats:=oPlanilla:numberFormats
lKey := oNumberFormats:queryKey("0,00", oLocalSettings, .t.)
If lKey = -1
lKey := oNumberFormats:addNew("0,00", oLocalSettings)
endif

But it does NOT do anything

Do you have a more complete example to share?

If you have any example of how to open an ods file, save some data in some cells and then save with another name, thank you.
It is a spreadsheet with many formulas, I am thinking that it would be better to have a formatted file and only save the data for the calculations.

Thank you very much for your attention



----- Mensaje original -----
De: "Klas Engwall" <har...@engwall.com>
Para: harbou...@googlegroups.com
Enviados: Sábado, 7 de Noviembre 2020 8:58:04
Asunto: Re: [harbour-users] libreoffice, numeric cell format

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/5e79c16d-9e2a-1ac2-7d29-43d30eb33235%40engwall.com.

Paola Bruccoleri

unread,
Nov 7, 2020, 9:37:14 AM11/7/20
to harbou...@googlegroups.com
it's works fine:

oLocalSettings:= oPlanilla:getPropertyValue ('CharLocale')
oLocalSettings:language := "es"
oLocalSettings:country := "es"
//oNumberFormats:= oPlanilla:numberFormats // estos dos son iguales
oNumberFormats:= oPlanilla:getNumberFormats() // estos dos son iguales
lKey := oNumberFormats:queryKey("#.###,00", oLocalSettings, .t.)
If lKey = -1
lKey := oNumberFormats:addNew("#.###,00", oLocalSettings) //"0,00"
endif

oHoja:GetCellByPosition(nColumna-1,nFila-1):NumberFormat:= lKey



----- Mensaje original -----
De: "Paola Bruccoleri" <pbruc...@adinet.com.uy>
Para: harbou...@googlegroups.com
Enviados: Sábado, 7 de Noviembre 2020 9:40:06
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/1922719301.3241740.1604752806681.JavaMail.zimbra%40vera.com.uy.

Klas Engwall

unread,
Nov 7, 2020, 3:10:01 PM11/7/20
to harbou...@googlegroups.com
Hi Paola;

> it's works fine:
>
> oLocalSettings:= oPlanilla:getPropertyValue ('CharLocale')
> oLocalSettings:language := "es"
> oLocalSettings:country := "es"
> //oNumberFormats:= oPlanilla:numberFormats // estos dos son iguales
> oNumberFormats:= oPlanilla:getNumberFormats() // estos dos son iguales
> lKey := oNumberFormats:queryKey("#.###,00", oLocalSettings, .t.)
> If lKey = -1
> lKey := oNumberFormats:addNew("#.###,00", oLocalSettings) //"0,00"
> endif
>
> oHoja:GetCellByPosition(nColumna-1,nFila-1):NumberFormat:= lKey

Good work :-)

If you still need the sample you asked about, here are a couple of
little demo apps. One writes a new .ods file and the other reads it,
modifies it and saves it under a different name. There is no safety net
:-). The code only scratches the surface of LibreOffice ole, there are
still lots of other things to get to terms with. Included is a little
mock-up of the infrastructure I use to keep track of the number formats
I use in the application.

Regards,
Klas
oletest_ods.zip

Paola Bruccoleri

unread,
Nov 7, 2020, 4:46:56 PM11/7/20
to harbou...@googlegroups.com
Thank you very much, in the next few days I will be studying it

----- Mensaje original -----
De: "Klas Engwall" <har...@engwall.com>
Para: harbou...@googlegroups.com
Enviados: Sábado, 7 de Noviembre 2020 17:09:51
Asunto: Re: [harbour-users] libreoffice, numeric cell format

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users

---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-users/2a255bb6-bead-cb08-3890-fb0051bdce2c%40engwall.com.
Reply all
Reply to author
Forward
0 new messages