select / unselect range of sheets

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
biasot
Posts: 1
Joined: Thu Mar 13, 2008 3:53 pm

select / unselect range of sheets

Post by biasot »

OOo Basic macro language :

I would like to select / unselect a range of sheets in a spreadsheet document, by index or by name, to clear contents of a specific cellrange in each of selected sheet.

I tried to scan an array contained sheet's name concerned, but as I have 40 sheets and 120 ranges of cells to clear it's very too long to do.

Clear range of cells after had selected a list of sheets should be a quicker process.

Thanks for your answers.
User avatar
Villeroy
Volunteer
Posts: 31344
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: select / unselect range of sheets

Post by Villeroy »

Code: Select all

n = thisComponent.Sheets.getCount()
Dim a(n -1) as new com.sun.star.table.CellRangeAddress
' B2:F1000 on each sheet:
For i = 0 to n -1
  a(i).Sheet = i
  a(i).StartColumn = 1
  a(i).StartRow= 1
  a(i).EndColumn = 5
  a(i).EndRow = 999
next

oBasket = thisComponent.createInstance("com.sun.star.sheet.SheetCellRanges")
oBasket.addRangeAddresses(a(), False)
with com.sun.star.sheet.CellFlags
  nWhat = .FORMULA + .STRING + .VALUE + .DATETIME
end with
oBasket.clearContents(nWhat)
 Edit: I forgot the DATETIME flag. Calc keeps track of constant date/times due to the variable NullDate property. 
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply