I wish to set the same properties for a number of columns on a sheet that are not adjacent to each other.
So far I have the following:
oColumnWidthD = oSheet.getCellRangeByName(“D1”)
oColumnWidthO = oSheet.getCellRangeByName(“O1”)
oColumnWidthZ = oSheet.getCellRangeByName(“Z1”)
My question is: Can I set these three ranges on a single line of code using one variable?
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.Sheets["Tabelle3"]
ranges = [ sheet[f"{char}1"] for char in "DOZ"]
And now tell us what you actually want, instead of asking how you want to solve it!
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.CurrentController.ActiveSheet
ranges = doc.createInstance('com.sun.star.sheet.SheetCellRanges')
for char in 'DOZ':
ranges.addRangeAddress(sheet[f'{char}1'].RangeAddress, True)
ranges.CellStyle = 'Good'