4D View Pro: Buscar y reemplazar con código

Traducido automáticamente de Deepl

A veces, cuando inicializa un documento de 4D View Pro, necesita encontrar algunos valores o etiquetas en él y reemplazarlos con datos emitidos desde 4D. Ahora es muy fácil con el comando VP Find comando. Gracias a este comando, puede encontrar datos, una fórmula o una etiqueta y reemplazarla en toda la hoja o sólo en una parte específica de ella.

Descubramos cómo.

Búsqueda VP de HDI

El comando VP Find te permite buscar un valor de texto dentro de un rango designado en el texto, las fórmulas o las etiquetas de un documento de 4D View Pro.

Por ejemplo, si desea realizar una búsqueda que distinga entre mayúsculas y minúsculas de la primera aparición de la palabra «Total» en el texto de las celdas:

$range:=VP All("ViewProArea")
// find the first cell that contains the word 'Total' in the current sheet
$result :=VP Find($range; "Total")
// Make the cell background yellow for the found cells
VP SET CELL STYLE ($result; New object("backColor"; "yellow"))

Ahora puedes refinar tu búsqueda para encontrar todas las celdas que contengan «Total» utilizando la propiedad all propiedad:

$range:=VP All("ViewProArea")
$condition :=New object
// Search in all values in the range
$condition .all:=True
// Find all cells containing the word 'Total' in the current sheet
$result :=VP Find($range; "Total"; $condition)
// Make the cell background yellow for the found cells
VP SET CELL STYLE ($result; New object("ba
ckColor»; «yellow»))

blank

  • Si quieres realizar una búsqueda por «Total» sin tener en cuenta el caso, sólo tienes que modificar la propiedad flags propiedad:

$range:=VP All("ViewProArea")
$condition :=New object
// Search the entire sheet
$condition .all:=True
// Search cells containing the word "Total" without considering the case
$condition .flags:=vk find flag ignore case
// Find all cells containing only the word 'Total' in the current sheet
$result :=VP Find($range; "Total"; $condition)
// Make the cell background yellow for the found cells
VP SET CELL STYLE ($result; New object(
«backColor»; «yellow»))

blank

  • Si desea sustituir todas las palabras «Total» encontradas por «4D», añada un parámetro con el texto de sustitución:

$range:=VP All("ViewProArea")
$condition :=New object
// Search the entire sheet
$condition .all:=True
// Search cells containing the word "Total" without considering the case
$condition .flags:=vk find flag ignore case
// Replace text in all cells containing only 'Total' with "4D"
$result :=VP Find($range; "Total"; $condition; "4D")
// Make the cell background yellow for the found cells
VP SET CELL STYLE ($result; New object("backColor"; "yellow"))

blank

Por supuesto, estas son sólo algunas de las posibilidades que permite el comando VP Find comando.

Para saber más, consulte el centro de documentación, por ejemplo, cómo buscar valores con comodines, buscar en fórmulas y mucho más.

Fabrice Mainguené
- Product Owner -Fabrice Mainguené se unió al equipo de 4D Program en noviembre de 2016. Como Product Owner, está a cargo de escribir las historias de usuario y luego traducirlas a especificaciones funcionales. Su papel es también asegurarse de que la implementación de la característica entregada cumple con las necesidades del cliente. Después de obtener una licenciatura en Ciencias de la Computación en el CNAM, Fabrice se unió a una pequeña empresa de publicación de software como desarrollador Windev. A continuación, trabajó para diferentes empresas del sector industrial y comercial como desarrollador de Windev y de la web, así como asesor técnico de nuevas funcionalidades.