在libre office calc

时间:2017-02-03 23:43:48

标签: libreoffice-calc

假设我有这个单元格:

Initial Enteries

然后由于某种原因,我想自动颠倒列的顺序,使其成为像这样的东西:

enter image description here

任何帮助将不胜感激!

3 个答案:

答案 0 :(得分:2)

快速步骤:

  • 在1上方插入新行
  • 用单调递增整数索引向右填充行。
  • 然后选择数据并按降序排列,因此索引最高的右列是第一个
  • 复制并粘贴结果


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