### Associate and Apply Templates in LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt This functionality links the current document to a language-specific LibreOffice guide template. It uses the loadStylesFromURL method to overwrite existing styles with those defined in the template. ```basic ' Llamar desde el menú LO SanityCheck > Preparar documento > Asociar plantilla ' Call from menu LO SanityCheck > Prepare document > Link template Sub Dlg_Plantillas If _Aux.F_Prueba_Sel = 0 then exit sub Call L10n.Trad_Plantilla If _Aux.F_Guardado = 0 Then Exit Sub ' Determina la plantilla según el idioma y versión ' Determines template based on language and version Select case L10n.F_getLang Case "es": TemplateURL = F_PathExtension & "/template/es/LO_Doc/LO_UG_Capitulos_26_ES.ott" Case "pt": TemplateURL = F_PathExtension & "/template/pt-BR/LO_Doc/LO_UG_Capitulos_26_PT.ott" Case else: TemplateURL = F_PathExtension & "/template/en-US/LO_Doc/LO_UG_Chapters_26_EN.ott" End Select ' Aplica la plantilla al documento ' Applies template to document S_loadTemplate(templateURL, oTemplate, templateName) S_applyTemplate(ThisComponent, templateUrl) End Sub ' Aplicar estilos desde plantilla ' Apply styles from template Sub S_applyTemplate(doc as object, templateUrl as string) Dim aArgs(0) As New com.sun.star.beans.PropertyValue aArgs(0).Name = "OverwriteStyles" aArgs(0).Value = TRUE doc.styleFamilies.loadStylesFromURL(templateURL, aArgs()) End Sub ``` -------------------------------- ### Verify and Clean Document Styles with LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt Automates the identification of non-standard paragraph and character styles. It includes routines to trigger style analysis and provides a method to remove specific styles by name from the document's style families. ```basic Sub CompEstilos Call L10n.Trad_Estilos If _Aux.F_EstilosPlantilla <> 0 then exit Sub Call _Aux.EliminaComentarios(E_Txt(0)) Avisos_Estilos_Ajenos("P") Avisos_Estilos_Ajenos("C") Call DialogoEstilos End Sub Sub EliminarEstilo(Familia As String, ItemName As String, ItemPos As Integer) If Familia = "P" Then Familia = "ParagraphStyles" ElseIf Familia = "C" Then Familia = "CharacterStyles" End If If ThisComponent.StyleFamilies.getByName(Familia).HasByName(ItemName) Then ThisComponent.StyleFamilies.getByName(Familia).removeByName(ItemName) End If End Sub ``` -------------------------------- ### Manage Document Fields with LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt Provides functions to initialize a dialog for editing user-defined properties (UDP), setting new property values, and querying existing ones. It interacts directly with the document's property set to ensure metadata consistency. ```basic Sub Dlg_Campos If _Aux.F_Guardado = 0 Then Exit Sub Call L10n.Trad_Campos oDlgCampos = CreateUNODialog(DialogLibraries.getByName("SanityCheck").getByName("DlgCampos")) Call Campos.Cargar_Parametros oDlgCampos.execute End Sub Sub Establece_UDP(NombreCampo As String, Valor As Variant) Dim oUDP : oUDP = ThisComponent.getDocumentProperties().UserDefinedProperties If oUDP.getPropertySetInfo().hasPropertyByName(NombreCampo) Then oUDP.setPropertyValue(NombreCampo, Valor) Else oUDP.addProperty(NombreCampo, 0, Valor) End If End Sub Function F_Consulta_UDP(NombreCampo As String) As String Dim oUDP : oUDP = ThisComponent.getDocumentProperties().UserDefinedProperties If oUDP.getPropertySetInfo().hasPropertyByName(NombreCampo) Then F_Consulta_UDP = oUDP.getPropertyValue(NombreCampo) Else F_Consulta_UDP = "" End If End Function ``` -------------------------------- ### Browse and Edit Image Properties in LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt Provides a mechanism to iterate through document images to verify and modify properties like descriptions, anchor types, and crop settings via a dialog interface. ```LibreOffice Basic Sub OnBtn_Cambiar_Desc_Img(oEv) oDlgImgs = oEv.Source.Context oImg.Description = oDlgImgs.getModel.getByName("Tx_Desc_Img").Text End Sub Sub OnBtn_Ancla(oEv) oDlgImgs = oEv.Source.Context oImg.AnchorType = 1 End Sub Function VerificarRecorte(oImg As Object) As Boolean Dim oRec : oRec = oImg.GraphicCrop() VerificarRecorte = (oRec.Right + oRec.Left + oRec.Top + oRec.Bottom <> 0) End Function ``` -------------------------------- ### Rename Document Objects in LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt Standardizes the naming of tables, images, and frames using a prefix and a sequential counter. It helps maintain a clean document structure by applying a consistent nomenclature based on the file name. ```LibreOffice Basic Function F_Renombra(Objetos As String, Optional separador) As String If IsMissing(separador) Then separador = "-" Dim Items As Object, prefijo As String If Objetos = "Tablas" Then Items = ThisComponent.TextTables() prefijo = "tb_" ElseIf Objetos = "Imagenes" Then Items = ThisComponent.GraphicObjects() prefijo = "img_" ElseIf Objetos = "Marcos" Then Items = ThisComponent.TextFrames() prefijo = "fram_" End If If Items.getCount() = 0 Then Exit Function Dim n_archivo As String, nombre As String, contador As String Dim oItem As Object, i As Integer n_archivo = left(Trim(FileNameoutofpath(ThisComponent.getURL())), 7) For i = 0 To Items.Count - 1 oItem = Items.getByIndex(i) If i < 10 Then contador = "00" & cStr(i) ElseIf i < 100 Then contador = "0" & cStr(i) Else contador = cStr(i) End If nombre = prefijo & n_archivo & separador & contador oItem.Name = nombre Next End Function ``` -------------------------------- ### Toggle Style Highlighting in LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt This macro toggles visual color highlighting for paragraph and character styles to assist in document auditing. It includes helper subroutines to modify background, character, and underline colors for specific styles. ```basic ' Llamar desde el menú LO SanityCheck > Alternar resalte ' Call from menu LO SanityCheck > Toggle Highlight Sub AlternarResalte Call _Aux.Carga_Tools Call L10n.Trad_Resaltes Call Resaltar End Sub ' Función para cambiar el color de fondo de un estilo de párrafo ' Function to change background color of a paragraph style Sub CambiaParrafo(Nombre As String, Resalte As String, Color As Variant, _ Optional Linea As String, Optional Color2 As Variant) ' Resalte: "F" = Fondo/Background, "L" = Letra/Character, "S" = Subrayado/Underline ' Ejemplo: CambiaParrafo("Text body", "F", F_Conv(Gris1)) End Sub ' Función para cambiar el color de fondo de un estilo de carácter ' Function to change background color of a character style Sub CambiaCaracter(Nombre As String, Resalte As String, Color, _ Optional Linea As String, Optional Color2) ' Ejemplo: CambiaCaracter("Emphasis", "F", F_Conv(Rojo)) End Sub ``` -------------------------------- ### Optimize Document Tables Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt A utility to standardize table properties, including margins, row behavior, and cell styles. It distinguishes between data tables and content tables to apply appropriate formatting. ```basic Sub Optimizar(oTabla As Object, Tipo As String) With oTabla .TableTemplateName = "" .CollapsingBorders = True .BreakType = 0 .Split = True .TopMargin = 0 .BottomMargin = 210 End With Dim i As Integer, oRow As Object For i = 0 To oTabla.Rows().count - 1 oRow = oTabla.getRows().getbyIndex(i) oRow.IsSplitAllowed = false oRow.IsAutoHeight = True Next If Tipo = "Datos" Then oTabla.HoriOrient = 2 oTabla.RelativeWidth = 90 oTabla.RepeatHeadline = True oTabla.HeaderRowCount = 1 Dim nRow, nCol, oCell For nRow = 0 To oTabla.getRows().getCount() - 1 For nCol = 0 To oTabla.getColumns().getCount() - 1 oCell = oTabla.getCellByPosition(nCol, nRow) oCell.BackColor = -1 If nRow = 0 Then Formato_Par(oCell.getText(), "Table Heading") Else Formato_Par(oCell.getText(), "Table Contents") End If Next Next End If End Sub ``` -------------------------------- ### Clean Direct Formatting in LibreOffice Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt Functions to remove manual text and paragraph formatting by resetting properties to default. It iterates through the main document body and text frames to ensure comprehensive cleanup. ```basic Function F_LimpiaTexto Dim oCursor As Object oCursor = ThisComponent.Text.createTextCursor() oCursor.gotoStart(True) oCursor.gotoEnd(True) oCursor.setAllPropertiesToDefault Dim oFrameEnum As Object, oFrame As Object, oFCursor As Object oFrameEnum = ThisComponent.TextFrames.createEnumeration() Do While oFrameEnum.hasMoreElements() oFrame = oFrameEnum.nextElement() oFCursor = oFrame.text.createTextCursor() oFCursor.gotostart(False) oFCursor.gotoEnd(True) oFCursor.setAllPropertiesToDefault Loop End Function Function F_LimpiaParrafos Dim oParEnum As Object, oPar As Object, oCursor As Object oParEnum = ThisComponent.Text.createEnumeration() oCursor = ThisComponent.Text.createTextCursor Do While oParEnum.hasMoreElements() oPar = oParEnum.nextElement() If oPar.supportsService("com.sun.star.text.Paragraph") Then oCursor.gotoRange(oPar.Anchor, False) oCursor.gotoendOfparagraph(True) oPar.NumberingStyleName = "" oCursor.setAllPropertiesToDefault End If Loop End Function ``` -------------------------------- ### Adjust Figures and Frames in LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt Automatically formats images and frames within a LibreOffice document. It applies consistent anchor types, vertical orientation, and metadata to ensure document uniformity. ```LibreOffice Basic Sub AjusteFiguras Call L10n.Trad_Imagenes If _Aux.F_TipoDoc <> "Capitulo" Then Exit Sub oImgs = ThisComponent.GraphicObjects() If oImgs.getCount = 0 Then Exit Sub Dlg_Figuras(F_Ajuste_Imagenes_Marcos) End Sub Function F_Ajuste_Imagenes_Marcos Dim oImgs As Object, oImg As Object, i As Integer oImgs = ThisComponent.GraphicObjects() oImg = oImgs.getbyIndex(0) With oImg .VertOrient = 2 .AnchorType = 1 .Name = " LibreOffice Logo" .Title = "LibreOffice Logo" .Description = "LibreOffice Logo" If _Aux.F_LOVersion >= 7.5 Then .Decorative = True End With For i = 1 To oImgs.Count - 1 oImg = oImgs.getByIndex(i) With oImg .AnchorType = 1 .VertOrient = 5 .VertOrientRelation = 2 .RelativeHeight = 0 .RelativeWidth = 0 If Not isEmpty(oImg.anchor.TextFrame) Then .getAnchor.ParaStyleName = "Figure" End If End With Next End Function ``` -------------------------------- ### Detect Broken Cross-References with LibreOffice Basic Source: https://context7.com/bantoniof/libreoffice-sanitycheck/llms.txt Scans the document for broken cross-references by enumerating text fields and checking for error strings. It updates fields and navigates the view cursor to the location of detected errors. ```basic Sub Dlg_Refs If _Aux.F_Prueba_Sel = 0 then exit sub Call L10n.Trad_Referencias oDlgRefs = CreateUNODialog(DialogLibraries.getByName("SanityCheck").getByName("DlgRefs")) oDlgRefs.execute End Sub Sub OnBtn_Buscar(oEv) Dim Vcursor As Object, oEnum as Object, oField As Object Dim s As String, i as Integer VCursor = ThisComponent.CurrentController.getViewCursor oEnum = ThisComponent.getTextFields().createEnumeration() ThisComponent.getTextFields().Refresh Do While oEnum.hasMoreElements() oField = oEnum.nextElement() oField.update s = ofield.getPresentation(False) If inStr(s, Ref_txt(1)) then VCursor.gotoRange(oField.Anchor.Start, False) i = i + 1 End If Loop End Sub ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.