How to assign number format to merge field with macro? [closed]

asked 2015-09-19 08:17:53 +0200

Decurtins gravatar image

updated 2021-05-21 22:50:26 +0200

Alex Kemp gravatar image

Hello Everybody

How do you set the NumberFormat of a Mail Merge Field in a Writer document with a macro? What I'm doing is: opening a .odt file and doing some sort of 'Data to Fields' procedure with a macro depending on the ID of the database record. The problem is: when setting the content coming out of the Database table in the mail merge fields, the format of this new content won't change to the format assigned to the field. Resetting the format of the field does not change how the content looks :(

I’ve got this:

oEnum = oDoc.getTextFields.createEnumeration 'Enumerate text fields.
    While oEnum.hasMoreElements
    thisField = oEnum.nextElement
    ilFormatDalField = thisField.NumberFormat

    'Xray thisField
    If thisField.SupportsService("") then 'Its a DB field.
      TFM = thisField.getTextFieldMaster 'Get text field master.
      If TFM.DataBaseName = DBname then 'The field is from the current database.
        fieldName = TFM.DataColumnName 'Get the field name.
        If DBrow.Columns.hasByName(fieldName) then 'Current DB row has this field name.
          'Xray DBrow.Columns.getByName(fieldName)
          s$ = DBrow.Columns.getByName(fieldName).getString(1) 'Get desired presentation string.
          'If IsDate(s$) then
          'print "ei in datum"
          'If IsNumeric(s$) then
          'print "ei in Numeric"
          'print s$
          thisField.CurrentPresentation = s$ 'Set the presentation.
          thisField.NumberFormat = IlFormatDalField
          'Xray thisField   
         Else ExtraFN = ExtraFN + 1 'Foreign field name count.
       Else ExtraDB = ExtraDB + 1 'Foreign database count.
    oDoc.Modified = true

The NumberFormat is being set, but is somehow not applied to the content of the Mail Merge Field (SwXTextField). In other words: the number/date/what ever just stays the same (i.e. the string that is returned form the DB).

what am I doing wrong?

as you probably see, I’m just hacking my way through the whole Macro-business Wink

thank you very much for your time!

LibreOffice, Mac OS 10.8.5

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2020-07-13 12:16:15.248987