Excel.View.Sheets内置的上下文菜单支持定制功能。
你可以去重新定义上下文菜单的CSS名称去展示不同的外观,例如:
.gc-ui-contextmenu-group-header {
font-weight:normal;
background-color:none;
}
你可以通过重写createMenuItemElement方法来修改上下文菜单的菜单选项和结构。
var excel = new Excel.View.Sheets.Workbook(document.getElementById('ss'));
function CustomMenuView() {}
CustomMenuView.prototype = new Excel.View.Sheets.ContextMenu.MenuView();
CustomMenuView.prototype.createMenuItemElement = function (menuItemData) {
// create menu item view by your self
// you can call super's createMenuItemElement here and only customize a few of menu item
// should return menu item view back
};
excel.contextMenu.menuView = new CustomMenuView();
你可以重写getCommandOptions方法,来实现在命令执行时提供更多的选项。
var excel = new Excel.View.Sheets.Workbook(document.getElementById('ss'));
function CustomMenuView() {}
CustomMenuView.prototype = new Excel.View.Sheets.ContextMenu.MenuView();
CustomMenuView.prototype.getCommandOptions = function (menuItemData, host, event) {
// for most of menu items,what they need are just the selections on sheets or activeSheet name
// but there may be some menu items need special parameters,like color picker,change color
// command need to know which color user clicked,so overwrite this function and return this
// parameter's value here.
};
excel.contextMenu.menuView = new CustomMenuView();