Michal Bilcik napsal(a):
Nazdar,
mam dokument vo Writeri a v nom nejake 2 prazdne user fields
(Insert/Fields/Other/User Field) typu Standard s nazvami fld_meno a
fld_email.
Ako im cez StarBasic priradim nejake hodnoty (napr. aby fld_name
bolo "Jozef Novak") ?
Viem ze by sa mal pouzit asi FieldMaster ale nejak sa v tom motam.
Nemate niekto nejaky priklad ?
Zkuste něco z tohoto:
***********************************************
Function SetDocumentVariable(ByVal strVarName As String, ByVal aValue As String
) As Boolean
Dim bFound As Boolean
Dim oActiveDocument, oTextmaster, sName, sService
Dim xMaster as object
On Error GoTo ErrorHandler
oActiveDocument = thisComponent
oTextmaster = oActiveDocument.getTextFieldMasters()
sName = "com.sun.star.text.FieldMaster.User." + strVarName
bFound = oActiveDocument.getTextFieldMasters.hasbyname(sName) ' check if
the variable exists
if bFound Then
xMaster = oActiveDocument.getTextFieldMasters.getByName( sName )
REM value MEMBER used for decimal values, CONTENT member for
Strings
'xMaster.value = aValue
xMaster.Content = aValue
Else ' Document variable doesn't exist yet
sService = "com.sun.star.text.FieldMaster.User"
xMaster =
thisComponent.createInstance("com.sun.star.text.FieldMaster.User")
xMaster.Name = strVarName
xMaster.Content = aValue
End If
SetDocumentVariable = True 'Success
Exit Function
ErrorHandler:
SetDocumentVariable = False
End Function
' vrati hodnotu zadaneho uzivatelskeho pole, neexistuje-li prazdny retezec
Function GetDocumentVariable(ByVal strVarName As String) As string
'Dim bFound As Boolean
Dim oActiveDocument, oTextmaster, sName, bFound, xMaster
oActiveDocument = thisComponent
oTextmaster = oActiveDocument.getTextFieldMasters()
sName = "com.sun.star.text.FieldMaster.User." + strVarName
bFound = oActiveDocument.getTextFieldMasters.hasbyname(sName) ' check if
the variable exists
if bFound Then
xMaster = oActiveDocument.getTextFieldMasters.getByName( sName )
REM value MEMBER used for decimal values, CONTENT member for
Strings
'xMaster.value = aValue
GetDocumentVariable = xMaster.Content
Else ' Document variable doesn't exist yet
GetDocumentVariable = ""
End If
End Function
'
'
'===========================================================================
' InsertDocumentVariable - routine used to insert a document variable into the
document
' user's textfield list and into the ad text, at the current cursor position
' In - strVarName: string with the name of the variable to be inserted
' oTxtCursor: current cursor object with the position to place the doc var
' Out - none
'===========================================================================
Sub InsertDocumentVariable(strVarName As String, oTxtCursor As Object)
Dim oActiveDocument, objField, objFieldMaster, sName, bFound
oActiveDocument = thisComponent
objField =
thisComponent.createInstance("com.sun.star.text.TextField.User")
sName = "com.sun.star.text.FieldMaster.User." + strVarName
bFound = oActiveDocument.getTextFieldMasters.hasbyname(sName) ' check
if the variable exists
if bFound Then
objFieldMaster =
oActiveDocument.getTextFieldMasters.getByName(sName)
objField.attachTextFieldMaster(objFieldMaster)
' Insert the Text Field
oText = thisComponent.Text
'oCursor = oText.createTextCursor()
'oCursor.gotoEnd(false)
oText.insertTextContent(oTxtCursor, objField, false)
End If
End Sub
'
'
'===========================================================================
' DeleteDocumentVariable - routine used to eliminate a document variable from
the document
' user's textfield list
' In - strVarName: string with the name of the variable to be deleted
' Out - none
'===========================================================================
Sub DeleteDocumentVariable(strVarName As String)
Dim oActiveDocument, objField, objFieldMaster, sName, bFound
oActiveDocument = thisComponent
objField =
oActiveDocument.createInstance("com.sun.star.text.TextField.User")
sName = "com.sun.star.text.FieldMaster.User." + strVarName
bFound = oActiveDocument.getTextFieldMasters.hasbyname(sName) ' check
if the variable exists
if bFound Then
objFieldMaster =
oActiveDocument.getTextFieldMasters.getByName(sName)
objFieldMaster.Content = ""
objFieldMaster.dispose()
End If
End Sub
*****************************************************
Tom B.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]