Guest User

Basic Libreoffice Macro for components

a guest
May 16th, 2021
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM  *****  BASIC  *****
  2.  
  3.  
  4. Sub Main
  5.  
  6.     ColorFirstColumn() 'This editor cursor has an effect on the Run!! Always place it in Main
  7.  
  8. End Sub
  9.  
  10.  
  11. Sub ColorFirstColumn
  12.  
  13.     Dim nRed As Long: nRed = RGB(255, 181, 197) 'Pink1
  14.  
  15.     Dim nGreen As Long: nGreen = RGB(144, 238, 144) 'light green
  16.  
  17.     Dim nBlue As Long: nBlue = RGB(174, 238, 238) 'PaleTurquoise2
  18.  
  19.     Dim nWhite As Long: nWhite = RGB(255, 255, 255) 'White
  20.  
  21.  
  22.  
  23.     Dim oDoc as Object
  24.  
  25.  
  26.  
  27.     oDoc = ThisComponent
  28.  
  29.     For rowno=0 To 500
  30.  
  31.         oCell = oDoc.Sheets(0).getCellByPosition(0,rowno)
  32.  
  33.         txt = oCell.getString()
  34.  
  35.         If (InStr(txt, "###")) Then
  36.  
  37.             oCell.CellBackColor = nRed
  38.  
  39.         ElseIf (InStr(txt, "##")) Then
  40.  
  41.             oCell.CellBackColor = nBlue
  42.  
  43.             oCell.HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
  44.  
  45.         ElseIf IsCellSubSubHdr(txt) Then
  46.  
  47.             oCell.CellBackColor = nGreen      
  48.  
  49.         Else
  50.  
  51.             oCell.CellBackColor = nWhite
  52.  
  53.         End If
  54.  
  55.         'Print i, txt
  56.  
  57.     Next
  58.  
  59. End Sub
  60.  
  61.  
  62. Function IsCellSubSubHdr(Optional txt$) As Boolean 'default False but txt can be Null so we need to test it
  63.  
  64.     Dim aSearchResult
  65.  
  66.     Dim oTextSearch: oTextSearch = CreateUnoService("com.sun.star.util.TextSearch")
  67.  
  68.     Dim aSrcOpt As New com.sun.star.util.SearchOptions
  69.  
  70.     Dim enLocale As New com.sun.star.lang.Locale
  71.  
  72.  
  73.  
  74.     If IsNull(txt) Then Exit Function
  75.  
  76.  
  77.  
  78.     With aSrcOpt
  79.  
  80.         .searchFlag = com.sun.star.util.SearchFlags.REG_EXTENDED
  81.  
  82.         .Locale = enLocale
  83.  
  84.         .algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
  85.  
  86.         .searchString = "^\s*[A-Z][a-z-]+"
  87.  
  88.     End With
  89.  
  90.     oTextSearch.setOptions(aSrcOpt)
  91.  
  92.     aSearchResult = oTextSearch.searchForward(txt, 0, Len(txt) - 1) 'cursor has to be set in
  93.  
  94.     If aSearchResult.subRegExpressions > 0 Then
  95.  
  96.         IsCellSubSubHdr = True
  97.  
  98.     End If  
  99.  
  100. End Function
Advertisement
Add Comment
Please, Sign In to add comment