由于CellType 牵扯到 Focus,键盘鼠标消息等,不建议在 enterCell 和 leaveCell 中动态改变 CellType。建议使用 自定义的 CellType 实现,比如:
var ComboCellForActiveCell = function () { };
ComboCellForActiveCell.prototype = new GC.Spread.Sheets.CellTypes.ComboBox();
ComboCellForActiveCell.prototype.paintValue = function (ctx, value, x, y, w, h, style, options) {
var sheet = options.sheet;
if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
GC.Spread.Sheets.CellTypes.ComboBox.prototype.paintValue.apply(this, arguments);
} else {
GC.Spread.Sheets.CellTypes.Base.prototype.paintValue.apply(this, arguments);
}
}
ComboCellForActiveCell.prototype.getHitInfo = function (x, y, cellStyle, cellRect, options) {
var sheet = options.sheet;
if (options.row === sheet.getActiveRowIndex() && options.col === sheet.getActiveColumnIndex()) {
return GC.Spread.Sheets.CellTypes.ComboBox.prototype.getHitInfo.apply(this, arguments);
} else {
return GC.Spread.Sheets.CellTypes.Base.prototype.getHitInfo.apply(this, arguments);
}
}
sheet.bind(GC.Spread.Sheets.Events.EnterCell, function (sender, args) {
sheet.repaint();
});
var cellType = new ComboCellForActiveCell();
cellType.items(['A', 'B', 'C', 'D']);
sheet.getCell(2, 2).cellType(cellType); |