RasmusK

New Member
Hi,

i have a problem with OpenOffice...i would like to format a cell in text-format "@".

I found this Code on OEHive, but it doesn't work (http://www.oehive.org/files/calcUtils.i.txt):

DEF VAR mpLocale AS COM-HANDLE NO-UNDO.
/* Get the current cell */
chCell = chWorkSheet:GetCellByPosition(ip_Col,ip_Row).
chNumberFormats = chWorkBook:NumberFormats.

chrFormats = chNumberFormats:queryKeys(16, mpLocale, FALSE).
/* this line produce the error */

CASE ip_DataType:
WHEN "Decimal" THEN chrNumberFormatString = "###,###,###,##0." + FILL("0", ip_Decimals).
OTHERWISE chrNumberFormatString = "".
END CASE. /* ip_DataType */
intNumberFormatId = chNumberFormats:queryKey(chrNumberFormatString, chLocalSettings, TRUE).​


The OO example macro code look like this:

Dim Doc As Object
Dim Sheet As Object
Dim Cell As Object
Dim NumberFormats As Object
Dim NumberFormatString As String
Dim NumberFormatId As Long
Dim LocalSettings As New com.sun.star.lang.Locale

Doc = ThisComponent
Sheet = Doc.Sheets(0)
Cell = Sheet.getCellByPosition(1,1)

Cell.Value = 23400.3523565

LocalSettings.Language = "en"
LocalSettings.Country = "us"

NumberFormats = Doc.NumberFormats
NumberFormatString = "@"

NumberFormatId = NumberFormats.queryKey(NumberFormatString, LocalSettings, True)
If NumberFormatId = -1 Then
NumberFormatId = NumberFormats.addNew(NumberFormatString, LocalSettings)
End If

MsgBox NumberFormatId
Cell.NumberFormat = NumberFormatId​


Has anyone an idea?

Thx
 
Top