Currency format in TEXT is Not Working in LibreOffice BASE Report

The Currency Format in TEXT is not working in LibreOffice BASE Report. Please help
The SCREEN SHOT is ATTACHED


The OUTPUT is
rptInvoice38.odt (19.6 KB)
and the base file I am working with
Contact Management.odb (36.3 KB)

Please help to resolve this issue as I cannot convert Currency to Text or Number to Text in LibreOffice Base report.

You are using a very special currency format. If you try the default formats of Report Builder it will work, but
[NatNum12 title USD]0.00
doesn’t work here also. Seems it isn’t implemented in ReportBuilder. The dialog will while creating this will show the result, but executing won’t work.
You could try to set this per macro. Start the report by macro from a form. Change the number format in all fields in table named Page_footer (start of the name, is numbered through the whole document…)

But note that it works with English (India) language, in AmountOwed field in Detail section. Took me several iterations to find the constellation.

@mikekaganski : Seems to be very buggy. If I set AmountOwed with [NatNum12 title USD]0.00 and English (India) it shows the right result.
If I try to set English (India) to the content of Page_footer the result from AmountOwed in Detail will shown as number only. Same language settings in Detail and Page_footer will destroy the number format.
It is also a problem of the whole report: What should the page footer show here? It will show always the 50 dollars from the first row, which is shown. If I set a group footer instead it will work. So it is a bug for the footer, but using the footer for this information doesn’t make sense.

1 Like

Here it is
eurinvoice38.odt (17.0 KB)

Thanks for your kind attention and ideas. I am not a technical IT Guy. Please help me out write the Macro code and create a Report based on LibreOffice Base Form.

Ok, let us try this:

SUB ReportStart
	DIM oDoc AS OBJECT, oRepDoc AS OBJECT, oReport AS OBJECT, oTables AS OBJECT, oTable AS OBJECT, oCell AS OBJECT
	DIM inT AS INTEGER, i AS INTEGER
	DIM arCellNames
	oDoc = ThisDatabaseDocument
	oRepDoc = oDoc.ReportDocuments
	oReport = oRepDoc.getByName("rptInvoice").open
	oTables = oReport.getTextTables()
	DIM locale As New com.sun.star.lang.Locale
	locale.Language = "en"
	locale.Country = "US"
	locale.Variant = "en"
	inNumFormat = FindCreateNumberFormatStyle("[NatNum12 title USD]0.00", oReport, locale)
	FOR inT = 0 TO oTables.count() - 1
		oTable = oTables.getByIndex(inT)
 		IF Left$(oTable.Name, 11) = "Page_footer" THEN
 			arCellNames = oTable.CellNames 
 			FOR i = 0 TO UBound(arCellNames)		
				oCell = oTable.getCellByName(arCellNames(i))
				oCell.NumberFormat = inNumFormat
			NEXT i
 		ENDIF
	NEXT inT
END SUB

Function FindCreateNumberFormatStyle(stFormat, Optional oDoc, Optional locale)
	DIM oDocument AS OBJECT, oFormats AS OBJECT
	DIM aLocale As New com.sun.star.lang.Locale
	DIM loformatNum AS LONG
	oDocument = IIf(IsMissing(oDoc), ThisComponent, oDoc)
	oFormats = oDocument.getNumberFormats()
	IF (Not IsMissing(locale)) THEN
		aLocale = locale
	END IF
	loformatNum = oFormats.queryKey(stFormat, aLocale, True)
	IF (loformatNum = -1) THEN
		loformatNum = oFormats.addNew(stFormat, aLocale)
		IF (formatNum = -1) THEN 
			loformatNum = 0
		END IF
	END IF
	FindCreateNumberFormatStyle = loformatNum
End Function

Create a button in one of the forms and start macro “ReportStart” by the button. It will automatically add the NumberFormat to all cells in Page_footer.
Number Format will depend on the locale of your system, so the number must be read by the second macro, the function “FindCreateNumberFormatStyle”.

Thanks for your kind co-operation. I assigned your macro “ReportStart” to a button in a form but nothing happens. I cannot figure out the cause of no action. May be my IT knowledge is too limited.
If you tested that, please send the final ‘odb’ file for my proper understanding.

OR

Can I assign any custom function like ‘SpellNumber’ to my currency field in LO Report, as it always works with CALC macro. (Source: Convert numbers into words - Microsoft Support)

Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace, Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "

' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")

' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _ "00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If

Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If

Count = Count + 1

Loop
Select Case Dollars
Case ""
Dollars = "No Dollars"
Case "One"
Dollars = "One Dollar"
Case Else
Dollars = Dollars & " Dollars"
End Select
Select Case Cents
Case ""
Cents = " and No Cents"
Case "One"
Cents = " and One Cent"
Case Else
Cents = " and " & Cents & " Cents"
End Select
SpellNumber = Dollars & Cents
End Function

' Converts a number from 100-999 into text

Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function

' Converts a number from 10 to 99 into text.

Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select

Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.
End If
GetTens = Result
End Function

' Converts a number from 1 to 9 into text.

Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function

Hope you understand my limitations. Eagerly waiting for your next suggestion.

[Code formatting added by robleyd]

@WaterDrop : Try the attached document and form invoices. Press the button for executing. You have to allow macro executing.
Contact Management.odb (37.5 KB)
But: What do you want with this kind of footer? It will show the value of the first row on every page…
Might be changing of the report will give a better result for what you ale planning:
Contact Management_2.odb (39.3 KB)

Surprised by so much arguing about string formatting, I take the liberty, being ignorant of all macros codes, to re-suggest in considering a report feaseability either by using report builder extension, or by setting an invoice template in writer accessing Tables by means of the upper right # icon in the top bar facilities.

My purpose is to try to remain as simple as i could.

Regards

Sometimes reading again and “not answering” would be simpler:

The start of this thread clearly shows report-builder in use. So the topic is a bug found while using report-builder. And your comment is therefore no way to a solution.

I am very sorry Wanderer! I unfortunately selected the wrong button.
With very best regards…

Thanks for your simple and easy to executable suggestions.

I am able to build the report with LO Base Form but couldn’t find any option to stop repeat at “Control Properties” of text field like Invoice No. which LO Base Report has.

Expecting any simple suggestion.

Thanks to all the community members.