Hi,
I have quite simple LibreOffice invoices, one file per invoice. There are
2 items in each invoice I would like to make dynamic.
1. Invoice number
2. Due date
For the invoice number, I created a user field "InvoiceNumber" and a macro
"UpdateInvoiceNumber", which automatically extracts the invoice number
from the filename and updates the field when the file is opened. This
works great as I simply can copy my invoice to the new name
(invoice-YYYY-MM-#NR-company) and the document is updated automatically
with YYYY/MM/#NR.
Now for the due date its more simple, but I cannot make it work. I used to
have 2 fields, invoice date and due date. Both are fixed date fields, the
second is 30 days off. To update them, I have to open the new invoice
copy, double-click the invoice date field, disable the 'fixed' (so that
is shows today's date), then make it fixed again, so it doesn't change the
next time I may edit it. Repeat the same procedure for the due date
fields. (twice, because I repeat the due date at the end in bold)
Now, what I intended to do was to create another user field of the due
date and automatically update both with the date set in the invoice date
field (which remains a fixed date) and add 30 days.
But the problem is that, contrary to user fields, date fields cannot be
referenced in Basic (likely because they do not have a name). Or at least
I cannot find it anywhere.
Below is the code I am using in LibreOffice to update the InvoiceNumber.
Can someone tell me how I can get the value of a (fixed) Date field ? Or
is there an easier way to update dates, and manipulate them elsewhere ?
----
Sub Main
UpdateInvoiceNumber()
Rem UpdateDueDate()
End Sub
Sub UpdateDueDate
Rem Don't know how to get to the invoice date fixed date field in the document
InvoiceDateField = thisComponent.getTextFieldMasters().getByName(
"com.sun.star.text.fieldmaster.InvoiceDate" )
end Sub
sub UpdateInvoiceNumber
InvoiceNumberField = thisComponent.getTextFieldMasters().getByName(
"com.sun.star.text.fieldmaster.User.InvoiceNumber" )
InvoiceNumberField.Content = InvoiceNumber()
disp = createUnoService("com.sun.star.frame.DispatchHelper")
disp.executeDispatch(thisComponent.CurrentController.Frame, ".uno:UpdateFields",
"", 0, Array())
end Sub
Function InvoiceNumber
InvoiceNumber = "ERROR"
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then
GlobalScope.BasicLibraries.LoadLibrary("Tools")
End If
InvoiceNumber = FileNameoutofPath(thisComponent.getURL(), "/")
InvoiceNumber = Mid(InvoiceNumber, 9, 11)
InvoiceNumber = ReplaceStr(InvoiceNumber, "-", "/")
End Function
Function ReplaceStr(myString As String, str1 As String, str2 As String)
ReplaceStr = join(split(myString, str1), str2)
End Function
----
PS Is there an easier way to look at the document object model than using
a watch in your macro editor ? Preferably something to search. That would
be so useful !
Thanks for your insights !
--
-- dag wieers, d...@wieers.com, http://dag.wieers.com/
-- dagit linux solutions, i...@dagit.net, http://dagit.net/
[Any errors in spelling, tact or fact are transmission errors]
--
Unsubscribe instructions: E-mail to users+h...@libreoffice.org
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/www/users/
All messages sent to this list will be publicly archived and cannot be deleted