LibreOffice Calc 並び替えのマクロ
2014年12月26日
2016年2月24日
ここ(http://www.oooforum.org/forum/viewtopic.phtml?t=67309)からいただいたコードがそのまますぐ動いた。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
Sub subSortRange Dim aSortFields(2) as New com.sun.star.util.SortField Dim aSortDesc(0) as New com.sun.star.beans.PropertyValue oDocument = ThisComponent oSheets = oDocument.Sheets oSheet = oSheets.getByIndex(0) oRange = oSheet.getCellRangeByPosition(1,0,5,6) 'range B1:F7 aSortFields(0).Field = 0 aSortFields(0).SortAscending = True 'sort ascending by column A aSortFields(1).Field = 2 aSortFields(1).SortAscending = False 'then sort descenting by column C aSortFields(2).Field = 1 aSortFields(2).SortAscending = True 'then sort ascending by column B aSortDesc(0).Name = "SortFields" aSortDesc(0).Value = aSortFields() oRange.Sort(aSortDesc()) End Sub |
oRange = oSheet.getCellRangeByPosition(1,0,5,6)で並び替える範囲を指定する。
aSortField().Field には並び替えキーに入れる列番号を指定する。
この例では、A列, C列, B列の順。
aSortFields().SortAscendingはTrueなら昇順、Falseなら降順。
