答案 0 :(得分:2)
快速步骤:
https://gr-plus.blogspot.com/2015/01/reverse-column-or-row-order-in-excel-or.html
答案 1 :(得分:1)
所以这是一种使用Libreoffice Basic和Libreoffice API的方法。
sub ReverseColumns()
oThisWorkbook = ThisComponent
oActiveSheet = oThisWorkbook.CurrentController.ActiveSheet
oRow1 = oActiveSheet.getRows().getByIndex(0)
aFilledCellsRow1 = oRow1.queryContentCells(1+2+4+16).getRangeAddresses()
if ubound(aFilledCellsRow1) = -1 then exit sub
lLastFilledColumnRow1 = aFilledCellsRow1(ubound(aFilledCellsRow1)).EndColumn
c = 0
for i = lLastFilledColumnRow1 to 1 step -1
oCellTargetColumn = oActiveSheet.getCellByPosition(c, 0)
oRangeAddressTargetColumn = oCellTargetColumn.RangeAddress
oActiveSheet.insertCells(oRangeAddressTargetColumn, com.sun.star.sheet.CellInsertMode.COLUMNS)
oCellTargetColumn = oActiveSheet.getCellByPosition(c, 0)
oCellAddressTargetColumn = oCellTargetColumn.CellAddress
oRangeSource = oActiveSheet.Columns.getByIndex(lLastFilledColumnRow1 + 1)
oRangeAddressSource = oRangeSource.RangeAddress
oActiveSheet.moveRange(oCellAddressTargetColumn, oRangeAddressSource)
c = c + 1
next
end sub
这首先确定第1行中的最后一个填充列。然后将完成列反转过程直到该列。
要了解Libreoffice中的宏,请从此处开始:https://wiki.documentfoundation.org/Macros
答案 2 :(得分:0)
如果这里的任何人想要颠倒行(而不是列)的顺序......我接受了宏代码posted by @Axel-Richter并对其进行了编辑,以便它可以做到:
sub ReverseRows()
oThisWorkbook = ThisComponent
oActiveSheet = oThisWorkbook.CurrentController.ActiveSheet
oColumn1 = oActiveSheet.getColumns().getByIndex(0)
aFilledCellsColumn1 = oColumn1.queryContentCells(1+2+4+16).getRangeAddresses()
if ubound(aFilledCellsColumn1) = -1 then exit sub
lLastFilledRowColumn1 = aFilledCellsColumn1(ubound(aFilledCellsColumn1)).EndRow
c = 0
for i = lLastFilledRowColumn1 to 1 step -1
oCellTargetRow = oActiveSheet.getCellByPosition(0, c)
oRangeAddressTargetRow = oCellTargetRow.RangeAddress
oActiveSheet.insertCells(oRangeAddressTargetRow, com.sun.star.sheet.CellInsertMode.ROWS)
oCellTargetRow = oActiveSheet.getCellByPosition(0, c)
oCellAddressTargetRow = oCellTargetRow.CellAddress
oRangeSource = oActiveSheet.Rows.getByIndex(lLastFilledRowColumn1 + 1)
oRangeAddressSource = oRangeSource.RangeAddress
oActiveSheet.moveRange(oCellAddressTargetRow, oRangeAddressSource)
c = c + 1
next
end sub