在Calc中使用键盘移动行

Modified on: Mon, 08 Oct 2018 10:00:06 +0800

如何使用键盘将行移动到其他位置?我找到了鼠标指南,但由于残疾,我无法使用老鼠这个。

请注意,我不打算“手动排序”,并且使用额外的“排序序号”列不是可行的解决方法。我知道Calc的优秀分类能力。

作者:dotancohen

最佳答案

我不确定是否有办法使用键盘“移动”行,但使用c& p并使用键盘插入/删除行应提供相同的功能:

  • 导航到要移动的行的第一个(最左边)单元格;
  • 点击 SHIFT + SPACE 选择整行;
  • 点击 CTRL + C 复制该行;
  • 点击 CTRL + - 删除当前行;
  • 导航到目标行;
  • 点击 ALT + I 打开Insert菜单;
  • 点击 R 插入一个新行(当前行将向下移动);
  • 点击 CTRL + V 将该行粘贴到新位置。

由于剪切和粘贴操作有时非常烦人,您可以创建一个用于剪切单元格的简单宏,另一个用于粘贴它们,将现有内容向下移动。

这是一个非常简单的“移动”选定单元格的代码:

Option Explicit

Sub CopyAndCut
    ' ---------------------------------------------------------
    ' define variables
    Dim document   as object
    Dim dispatcher as Object
    Dim oSelections As Object
    ' ---------------------------------------------------------
    ' get access to the document and selections (if any)
    document    = ThisComponent.CurrentController.Frame
    oSelections = ThisComponent.getCurrentSelection()
    If IsNull(oSelections) Then Exit Sub        
    ' ---------------------------------------------------------
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
    dispatcher.executeDispatch(document, ".uno:Cut", "", 0, Array())
    ' -------------------------------------------------------------
    ' Check the width of the selection - if 1024 columns, we assume
    ' the complete row was selected and should get deleted
    If 1024 = oSelections.Columns.getCount() Then
        dispatcher.executeDispatch(document, ".uno:DeleteRows", "", 0, Array())
    End If
End Sub

Sub InsertWithMoveDown
    ' ---------------------------------------------------------
    ' define variables
    Dim document   as object
    Dim dispatcher as object
    ' ---------------------------------------------------------
    ' get access to the document
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    ' ---------------------------------------------------------
    ' Paste contents with "Move Down" option
    Dim args1(5) as New com.sun.star.beans.PropertyValue
    args1(0).Name = "Flags"
    args1(0).Value = "A"
    args1(1).Name = "FormulaCommand"
    args1(1).Value = 0
    args1(2).Name = "SkipEmptyCells"
    args1(2).Value = false
    args1(3).Name = "Transpose"
    args1(3).Value = false
    args1(4).Name = "AsLink"
    args1(4).Value = false
    args1(5).Name = "MoveMode"
    args1(5).Value = 0
    dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args1())
End Sub

Sub InsertWithMoveRight
    ' ---------------------------------------------------------
    ' define variables
    Dim document   as object
    Dim dispatcher as object
    ' ---------------------------------------------------------
    ' get access to the document
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    ' ---------------------------------------------------------
    ' Paste contents with "Move Right" option
    Dim args1(5) as New com.sun.star.beans.PropertyValue
    args1(0).Name = "Flags"
    args1(0).Value = "A"
    args1(1).Name = "FormulaCommand"
    args1(1).Value = 0
    args1(2).Name = "SkipEmptyCells"
    args1(2).Value = false
    args1(3).Name = "Transpose"
    args1(3).Value = false
    args1(4).Name = "AsLink"
    args1(4).Value = false
    args1(5).Name = "MoveMode"
    args1(5).Value = 1
    dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args1())
End Sub

将代码复制到用户库后,只需将CopyAndCut分配给,例如 Alt + C InsertWithMoveDown到,例如, Alt + V InsertWithMoveRight到例如 Alt + R (所有这些快捷方式默认为空)。

现在,您可以使用鼠标或键盘选择单元格或行,使用 Alt + C 剪切它们,移动到目标单元格,然后使用粘贴它们Alt + V Alt + R

作者:,tohuwawohu

相关问答

添加新评论