[RESUELTO] Reemplazar cambiando el tamaño de la letra

Desarrollo de Macros y programación en UNO, usar las API, llamar programas externos...
Responder
Ambrosio
Mensajes: 24
Registrado: Lun Abr 23, 2018 6:33 pm

[RESUELTO] Reemplazar cambiando el tamaño de la letra

Mensaje por Ambrosio »

Hola,
Intento Buscar y Reemplazar dentro de un texto. Buscar un carácter (o una letra) y Reemplazarla pero destacándola con un tamaño mayor. En el Writer esto es posible desde el menú:
Imagen
Editar | Busca y reemplaza… | Otras opciones | Formato | Tamaño de letra

Pero al hacer una macro con “Gravar una macro”, no cambia el tamaño:

Código: Seleccionar todo

args1(11).Name = "SearchItem.SearchString"
args1(11).Value = "p"
args1(12).Name = "SearchItem.ReplaceString"
args1(12).Value = "P"
args1(13).Name = "SearchItem.Locale"
args1(13).Value = 255
args1(14).Name = "SearchItem.ChangedChars"
args1(14).Value = 2
Nota: parece que sí que cambia el tamaño si no haces ninguna otra “búsqueda” ya que se queda por defecto el tamaño de letra fijado en el cuadro de Buscar-Reemplazar, pero en realidad la macro no está cambiando el tamaño de la letra, cosa fácil de comprovar haciendo una nueva búsqueda sin formato y después volviendo a aplicar la macro.

Después he intentado hacer lo mismo siguiendo un ejemplo de tu libro “Aprendiendo Ooo Basic” (pag. 242); quiero buscar un “ “ (espacio en blanco) y sustituirlo por una letra “p”. He comprovado que encuentra el “espacio en blanco” pero no lo sustituye por la letra “p”:

Código: Seleccionar todo

Dim tc, oRD
tc = ThisComponent
oRD = tc.createReplaceDescriptor
oRD.setSearchString("= " )    
oRD.setReplaceString( "=p" )
tc.replaceAll(oRD)
Si consiguiera que encuentre todos los espacios en blanco (o una letra en concreto) y la sustituyera, todavía no sé cómo podría indicarle que quiero que al sustituir aumente el tamaño de la letra para destacarlo más.

Gracias por adelantado,

Ambrosio Gassol
Última edición por fornelasa el Lun Sep 24, 2018 7:51 pm, editado 2 veces en total.
Razón: Agregar icono verde de resuelto.
windows 7 // LibreOffice_5.4.5_Win_x86
Ambrosio
Mensajes: 24
Registrado: Lun Abr 23, 2018 6:33 pm

Re: Reemplazar cambiando el tamaño de la letra

Mensaje por Ambrosio »

Hola,
Continuo sin conseguir poder reemplazar una letra por la misma pero de un tamaño mayor para destacarla.
He provado el siguiente código pero no sé porque no funciona:

Código: Seleccionar todo

Sub ReplaceFormatting
  REM original code : Alex Savitsky
  REM modified by : Laurent Godard
  REM modified by : Andrew Pitonyak
  REM The purpose of this macro is to surround all BOLD elements with {{ }}
  REM and change the Bold attribute to NORMAL by using a regular expression.

  Dim oReplace  ', document
  Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
  Dim ReplAttributes(0) as new com.sun.star.beans.PropertyValue

  oReplace = ThisComponent.createReplaceDescriptor()

'  oReplace.SearchString = ".*"           'Regular expression. Match any text
  oReplace.SearchString = "p"
'  oReplace.ReplaceString = "{{ & }}"     'Note the & places the found text back
  oReplace.ReplaceString = "P"
  oReplace.SearchRegularExpression=True  'Use regular expressions
  oReplace.searchStyles=True             'We want to search styles

  oReplace.searchAll=True                'Do the entire document

  REM This is the attribute to find
'  SrchAttributes(0).Name = "CharWeight"
  SrchAttributes(0).Name = "CharHeight"
'  SrchAttributes(0).Value =com.sun.star.awt.FontWeight.BOLD
  SrchAttributes(0).Value = 12

  REM This is the attribute to replace it with
'  ReplAttributes(0).Name = "CharWeight"
  ReplAttributes(0).Name = "CharHeight"
'  ReplAttributes(0).Value =com.sun.star.awt.FontWeight.NORMAL
  ReplAttributes(0).Value = 48

  REM Set the attributes in the replace descriptor
  oReplace.SetSearchAttributes(SrchAttributes())
  oReplace.SetReplaceAttributes(ReplAttributes())


  REM Now do the work!
  ThisComponent.replaceAll(oReplace)

End Sub
He cambiado el atributo CharWeight por CharHeigt
windows 7 // LibreOffice_5.4.5_Win_x86
Avatar de Usuario
fornelasa
Mensajes: 3268
Registrado: Jue Feb 17, 2011 8:30 pm
Ubicación: Estado de México, México.

Re: Reemplazar cambiando el tamaño de la letra

Mensaje por fornelasa »

Ambrosio escribió:Hola,
Continuo sin conseguir poder reemplazar una letra por la misma pero de un tamaño mayor para destacarla.
Creo no te he entendido bien, pues eso puede hacerse hasta con la grabadora de macros.
Por ejemplo para la letra "e" primero selecciona el texto de trabajo y después:

Código: Seleccionar todo

sub Main
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(18) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 0
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 71680
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = "e"
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = ""
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 1
args1(18).Name = "Quiet"
args1(18).Value = true

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FontHeight.Height"
args2(0).Value = 18
args2(1).Name = "FontHeight.Prop"
args2(1).Value = 100
args2(2).Name = "FontHeight.Diff"
args2(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args2())


end sub
lo 6.2.0 | aoo 4.1.6 | win 7/10
¡Un aplauso para todos los que luchan por proteger y promover la Web abierta!
Ambrosio
Mensajes: 24
Registrado: Lun Abr 23, 2018 6:33 pm

Re: Reemplazar cambiando el tamaño de la letra

Mensaje por Ambrosio »

Hola,

Esa segunda parte de tu código era lo que me faltaba:

Código: Seleccionar todo

rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FontHeight.Height"
args2(0).Value = 18
args2(1).Name = "FontHeight.Prop"
args2(1).Value = 100
args2(2).Name = "FontHeight.Diff"
args2(2).Value = 0

dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args2())

Gracias, ya me funciona
windows 7 // LibreOffice_5.4.5_Win_x86
Responder