addSpan how to emit spreadsheet event like mergeEvent

Posted by: 122368177 on 30 March 2020, 7:12 pm EST

  • Posted 30 March 2020, 7:12 pm EST

    export default class CustomContextMenuView extends GC.Spread.Sheets.ContextMenu.MenuView {
    public customMenuData = [
    text: 'merge cells',
    name: 'gc.spread.customContextMenu.merge',
    command: this.handleCustomCommand,
    workArea: 'viewportcorner'
    constructor() {
    createMenuItemElement(menuItemData: GC.Spread.Sheets.ContextMenu.IMenuItemData): HTMLElement {
    const menuElement = super.createMenuItemElement(menuItemData)
    return menuElement
    getCommandOptions(menuItemData: GC.Spread.Sheets.ContextMenu.IMenuItemData, host: Record<string, any>, event: Record<string, any>): any {
    const name = || ''
    if (name.indexOf('customContextMenu') > -1) {
    return { menuItemData, host, event }
    } else {
    super.getCommandOptions(menuItemData, host, event)
    handleCustomCommand(context: GC.Spread.Sheets.Workbook, options: any) {
    const name =
    const activeSheet = context.getActiveSheet()
    const selections = activeSheet.getSelections()
    switch (name) {
    case 'gc.spread.customContextMenu.merge':
    if (selections.length === 1) {
    const { row, col, rowCount, colCount } = selections[0]
    activeSheet.addSpan(row, col, rowCount, colCount, GC.Spread.Sheets.SheetArea.viewport)

    spreadsheet how to bind mergeChanged event,there is not event type
  • Marked as Answer

    Replied 31 March 2020, 9:37 pm EST


    The events are provided only for the actions performed by the end-user such as UI interaction like changing cell, editing value etc. Events are not fired when using the API to manipulate spread, the general idea is when using the underlying API, we are already aware of the changes we are making so we could easily perform any additional actions required.
    In this case, if you need an event for merging, you may create a custom event bus and dispatch the event after calling the addSpan method. Please refer to the following code snippet and the attached sample demonstrating the same:
    //addSpan to the Sheet
    if (selections.length === 1) {
    const { row, col, rowCount, colCount } = selections[0];
    activeSheet.addSpan(row, col, rowCount, colCount, GC.Spread.Sheets.SheetArea.viewport);
    // span added dispatch custom event
    publish("spanAdded", {
    spread: spread,
    sheet: sheet,
    row: sel.row,
    col: sel.col,
    rowCount: sel.rowCount,
    colCount: sel.colCount

  • Replied 31 March 2020, 10:21 pm EST

    Many thanks for your answer.And your code open another door for me.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels