Skip to content

Instantly share code, notes, and snippets.

@Kennyl
Last active October 5, 2021 04:22
Show Gist options
  • Save Kennyl/317c376e17bd78af3905de2d8c375bea to your computer and use it in GitHub Desktop.
Save Kennyl/317c376e17bd78af3905de2d8c375bea to your computer and use it in GitHub Desktop.
LibreOffice Calc Macro Basic Script
''' Basic Script for Libre Office Calc , Demo AutoFill
Sub AutoFill
Sheets = ThisComponent.getSheets()
oSheet = Sheets.getByName("MemberList")
oRange = oSheet.getCellRangeByName("A2:A6") ' A4:A6 has no data
oRange.fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM,1)
End Sub
''' Basic Script for Libre Office Calc , Demo Copy and Paste in Macro
Sub CopyExample
Sheets = ThisComponent.Sheets
SheetCopy = Sheets.getByName("MemberList") 'From
CopyRange = SheetCopy.getCellRangeByName("A1:M250")
CopyAddress = CopyRange.RangeAddress
SheetPaste = Sheets.getByName("Sheet5") 'To
PasteCell = SheetPaste.getCellRangeByName("B5")
PasteAddress = PasteCell.CellAddress
SheetCopy.CopyRange(PasteAddress, CopyAddress)
MsgBox "CopyAddress :" & Chr(13) &_
" " & CopyRange.AbsoluteName &_
Chr(13) & Chr(13) &_
"PasteAddress :" & Chr(13) &_
" " & PasteCell.AbsoluteName
End Sub
''' Basic Script for Libre Office Calc , Demo Search
Sub SearchExample
Sheets = ThisComponent.getSheets()
oSheet = Sheets.getByName("MemberList")
oDescriptor = oSheet.createSearchDescriptor()
With oDescriptor
.SearchString = Sheets.getByName("Main").getCellRangeByName("B3:B3").getString()
.SearchWords = true 'The attributes default to False
.SearchCaseSensitive = False 'So setting one to False is redundant
End With
' cell = sheet.getCellRangeByName("A1:C10").findFirst(oDescriptor)
cell = oSheet.findFirst(oDescriptor) ' whole sheet
If not isNull(cell) then
MsgBox "Row = " & cell.CellAddress.Row & Chr(13) &_
"Column = " & cell.CellAddress.Column
Else MsgBox "Not Found!"
'''
EndIf
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment