Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 2.17 KB

1.单元格导航行为.md

File metadata and controls

41 lines (35 loc) · 2.17 KB

单元格导航行为

Excel.View.Sheets 提供的导航操作定义在 Excel.View.Sheets.Commands 中。

  • moveToNextCell:移动到下一个单元格(默认操作是按下 Tab 键)。
  • moveToPreviousCell: 移动到前一个单元格(默认操作是同时按下 Shift 键和 Tab 键)。
  • selectNextControl: 选中 excel.nextControl 所指定的元素。如果没有设置,则自动检测。
  • selectPreviousControl:选中 excel.previousControl 所指定的元素。如果没有设置,则自动检测。
  • moveToNextCellThenControl: 移动到下一个单元格时,如果有活动单元格是最后一个可见的单元格,则选中下一个控件。
  • moveToPreviousCellThenControl: 移动到前一个单元格时,如果有活动单元格是第一个可见的单元格,则选中前一个控件。 通过 nextControl 和 previousControl 方法来设置选择控件。例如:
// set next & previous control
excel.nextControl(document.getElementById('myNextControl'));
excel.previousControl(document.getElementById('myPreviousControl'));

// set the value to undefined without using auto detect
excel.nextControl(undefined);

调用 register 方法来设置导航键和相应的操作。例如:

// set Tab to select next control
excel.commandManager().register('selectNextControl', Excel.View.Sheets.Commands.selectNextControl, Excel.View.Commands.Key.tab, false, false, false, false);
// set Shift + Tab to select previous control
excel.commandManager().register('selectPreviousControl', Excel.View.Sheets.Commands.selectPreviousControl, Excel.View.Commands.Key.tab, false, true, false, false);

register 方法的参数列举如下:

  • name: 操作的名称。
  • execute: 操作的执行函数。
  • key: 按键的 Unicode 编码。
  • ctrl: 按下 Ctrl 键时为 true,否则为 false。
  • shift: 按下 Shift 键时为 true,否则为 false。
  • alt: 按下 Alt 键时为 true,否则为 false。
  • meta: 按下 Macintosh 设备上的 Command 键或者 Windows 设备上的 Windows 键时为 true,否则为false。

当 excel 失去焦点时,调用 hideSelection 方法来隐藏选择效果。例如:

excel.options.hideSelection = true;