Saltar al contenido principal
Versión: 20 R9 BETA

WP Insert formula

WP Insert formula ( targetObj ; formula ; mode {; rangeUpdate} ): Object

ParámetrosTipoDescripción
targetObjObjectRango o elemento o documento 4D Write Pro
formulaObjectFormula object OR Object with formula and name properties
modeNumberModo de inserción
rangeUpdateNumberIncludes or excludes the inserted content within the range
ResultadoObjectText range object reprsenting the result of the formula

Descripción

El comando WP Insert formula inserta una formula en targetObj de acuerdo con el mode de inserción especificado y devuelve el rango de texto resultante.

En el parámetro targetObj, puede pasar:

  • un rango, o
  • an element (table / row / cell(s) / paragraph / body / header / footer / section / subsection / inline picture), or
  • un documento 4D Write Pro.

In the formula parameter, pass the 4D formula to evaluate. Puede pasar:

PropiedadTipoDescription
nameTextNombre que se mostrará para la fórmula en el documento
formulaObjectThe formula object created by the Formula or Formula from string command

When you use an object with a formula name, this name is displayed in the document instead of the formula reference when formulas are displayed as reference, and in the formula tip when displayed as value or symbols. If the name property contains an empty string or is omitted, it is removed from the object and the formula is displayed by default. Para más información, vea la página Gestión de formulas.

In the mode parameter, pass one of the following constants to indicate the insertion mode to be used:

ConstanteTipoValorComentario
wk appendInteger2Insertar el contenido al final del objetivo
wk prependInteger1Insertar el contenido al principio del objetivo
wk replaceInteger0Sustituir contenido de destino
  • If targetObj is a range, you can use the optional rangeUpdate parameter to pass one of the following constants to specify whether or not the inserted formula is included in the resulting range:
ConstanteTipoValorComentario
wk exclude from rangeInteger1Contenido insertado no incluido en el rango actualizado
wk include in rangeInteger0Contenido insertado incluido en el rango actualizado (por defecto)

If you do not pass a rangeUpdate parameter, by default the inserted formula is included in the resulting range.

  • Si targetObj no es un rango, rangeUpdate se ignora.
nota

Keep in mind that, when called, the formula object is evaluated within the context of the database or component that created it.

Ejemplo 1

To replace all current date formulas with formatted strings:

 var $_formulas : Collection
var $find;$newFormula : Object

// define the formula to find
$find:=Formula(Current date)

// define the replacement formula
$newFormula:=Formula(String(Current date;System date long))

// find all formulas in the document
$_formulas:=WP Get formulas(WriteProArea)

// query the collection from WP Get formulas
$_formulas:=$_formulas.query("formula.source =:1";$find.source)

// then replace each formula
For each($formula;$_formulas)
WP Insert formula($formula.range;$newFormula;wk replace)
End for each

Ejemplo 2

You want to use a formula name for the customer name:

  //add some data
$data:=New object("customer";New object("lastname";"Smith";"firstname";"John"))
WP SET DATA CONTEXT(WPArea;$data)

//create a formula object with a name
$o:=New object
$o.formula:=Formula(This.data.customer.firstname+" "+This.data.customer.lastname)
$o.name:="Customer name"

//inserts as text
$range:=WP Text range(WPArea;wk start text;wk end text)
WP SET TEXT($range;"Dear ";wk append)
WP Insert formula($range;$o;wk append)

Resultado:

Ejemplo 3

Desea resaltar una fórmula en amarillo:

WParea:=WP New
WP SET TEXT(WParea; "The project was completed on: "; wk append)
$range1:=WP Insert formula(WParea; Formula(Current date); wk append)

WP SET ATTRIBUTES($range1; wk background color; "yellow")

Resultado:

Ver también

Managing formulas
WP COMPUTE FORMULAS
WP FREEZE FORMULAS
WP Get formulas