Compartilhar via


Excel.WorksheetChangedEventArgs interface

Fornece informações sobre a planilha que levantou o evento alterado.

Comentários

[ Conjunto de API: ExcelApi 1.7 ]

Propriedades

address

Obtém o endereço do intervalo que representa a área alterada de uma planilha específica.

changeDirectionState

Representa uma alteração na direção em que as células em uma planilha mudarão quando uma célula ou células forem excluídas ou inseridas. Isso inclui os dois cenários a seguir. 1. A direção (como para baixo ou para a direita) que as células existentes mudarão quando uma nova célula ou células forem inseridas em uma planilha. 2. A direção (como para cima ou para a esquerda) que as células restantes mudarão quando uma célula ou células forem excluídas de uma planilha.

changeType

Obtém o tipo de alteração que representa como o evento alterado é disparado. Confira Excel.DataChangeType detalhes.

details

Representa as informações sobre os detalhes da alteração. Essa propriedade pode ser recuperada quando o evento alterado é disparado em uma única célula. Se o evento alterado for disparado em várias células, essa propriedade não poderá ser recuperada.

source

Obtém a origem do evento. Confira Excel.EventSource detalhes.

triggerSource

Representa a origem do gatilho do evento. Por exemplo, identifica se esse suplemento local dispara o evento.

type

Obtém o tipo do evento. Confira Excel.EventType detalhes.

worksheetId

Obtém a ID da planilha na qual os dados foram alterados.

Métodos

getRange(ctx)

Obtém o intervalo que representa a área alterada de uma planilha específica.

[ Conjunto de API: ExcelApi 1.8 ]

getRangeOrNullObject(ctx)

Obtém o intervalo que representa a área alterada de uma planilha específica. Pode retornar o objeto null.

[ Conjunto de API: ExcelApi 1.8 ]

Detalhes da propriedade

address

Obtém o endereço do intervalo que representa a área alterada de uma planilha específica.

address: string;

Valor da propriedade

string

Comentários

[ Conjunto de API: ExcelApi 1.7 ]

changeDirectionState

Representa uma alteração na direção em que as células em uma planilha mudarão quando uma célula ou células forem excluídas ou inseridas. Isso inclui os dois cenários a seguir. 1. A direção (como para baixo ou para a direita) que as células existentes mudarão quando uma nova célula ou células forem inseridas em uma planilha. 2. A direção (como para cima ou para a esquerda) que as células restantes mudarão quando uma célula ou células forem excluídas de uma planilha.

changeDirectionState: Excel.ChangeDirectionState;

Valor da propriedade

Comentários

[ Conjunto de API: ExcelApi 1.14 ]

Exemplos

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-worksheet.yaml

async function onChange(event: Excel.WorksheetChangedEventArgs) {
    // This function is an event handler that returns the address, trigger source, 
    // and insert or delete shift directions of the change.
    await Excel.run(async (context) => {
        // Return the address where change occurred.
        console.log(`Handler for worksheet onChanged event has been triggered.`);
        console.log(`    Data changed address: ` + event.address);

        // Return the source of the event that triggered the change.
        console.log(`    Data change trigger source: ` + event.triggerSource);

        // Note:insertShiftDirection and deleteShiftDirection are exclusive and both enums can't have a value at the same time. 
        // If one has a value, then the other will return undefined.

        // If the insert shift direction is defined, return it.
        if (event.changeDirectionState.insertShiftDirection) {
            console.log(`    Cells inserted shift direction: ` + event.changeDirectionState.insertShiftDirection);
        }

        // If the delete shift direction is defined, return it.
        if (event.changeDirectionState.deleteShiftDirection) {
            console.log(`    Cells deleted shift direction: ` + event.changeDirectionState.deleteShiftDirection);
        }
    });
}  

...

// This function deletes data from a range and sets the delete shift direction to "up".
await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    const range = sheet.getRange("A5:F5");
    range.delete(Excel.DeleteShiftDirection.up);
});

changeType

Obtém o tipo de alteração que representa como o evento alterado é disparado. Confira Excel.DataChangeType detalhes.

changeType: Excel.DataChangeType | "Unknown" | "RangeEdited" | "RowInserted" | "RowDeleted" | "ColumnInserted" | "ColumnDeleted" | "CellInserted" | "CellDeleted";

Valor da propriedade

Excel.DataChangeType | "Unknown" | "RangeEdited" | "RowInserted" | "RowDeleted" | "ColumnInserted" | "ColumnDeleted" | "CellInserted" | "CellDeleted"

Comentários

[ Conjunto de API: ExcelApi 1.7 ]

details

Representa as informações sobre os detalhes da alteração. Essa propriedade pode ser recuperada quando o evento alterado é disparado em uma única célula. Se o evento alterado for disparado em várias células, essa propriedade não poderá ser recuperada.

details: Excel.ChangedEventDetail;

Valor da propriedade

Comentários

[ Conjunto de API: ExcelApi 1.9 ]

Exemplos

// This function would be used as an event handler for the Worksheet.onChanged event.
async function onWorksheetChanged(eventArgs) {
    await Excel.run(async (context) => {
        const details = eventArgs.details;
        const address = eventArgs.address;

        // Print the before and after types and values to the console.
        console.log(`Change at ${address}: was ${details.valueBefore}(${details.valueTypeBefore}),`
            + ` now is ${details.valueAfter}(${details.valueTypeAfter})`);
        await context.sync();
    });
}

source

Obtém a origem do evento. Confira Excel.EventSource detalhes.

source: Excel.EventSource | "Local" | "Remote";

Valor da propriedade

Excel.EventSource | "Local" | "Remote"

Comentários

[ Conjunto de API: ExcelApi 1.7 ]

triggerSource

Representa a origem do gatilho do evento. Por exemplo, identifica se esse suplemento local dispara o evento.

triggerSource: Excel.EventTriggerSource | "Unknown" | "ThisLocalAddin";

Valor da propriedade

Excel.EventTriggerSource | "Unknown" | "ThisLocalAddin"

Comentários

[ Conjunto de API: ExcelApi 1.14 ]

Exemplos

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/30-events/events-worksheet.yaml

async function onChange(event: Excel.WorksheetChangedEventArgs) {
    // This function is an event handler that returns the address, trigger source, 
    // and insert or delete shift directions of the change.
    await Excel.run(async (context) => {
        // Return the address where change occurred.
        console.log(`Handler for worksheet onChanged event has been triggered.`);
        console.log(`    Data changed address: ` + event.address);

        // Return the source of the event that triggered the change.
        console.log(`    Data change trigger source: ` + event.triggerSource);

        // Note:insertShiftDirection and deleteShiftDirection are exclusive and both enums can't have a value at the same time. 
        // If one has a value, then the other will return undefined.

        // If the insert shift direction is defined, return it.
        if (event.changeDirectionState.insertShiftDirection) {
            console.log(`    Cells inserted shift direction: ` + event.changeDirectionState.insertShiftDirection);
        }

        // If the delete shift direction is defined, return it.
        if (event.changeDirectionState.deleteShiftDirection) {
            console.log(`    Cells deleted shift direction: ` + event.changeDirectionState.deleteShiftDirection);
        }
    });
}  

type

Obtém o tipo do evento. Confira Excel.EventType detalhes.

type: "WorksheetChanged";

Valor da propriedade

"WorksheetChanged"

Comentários

[ Conjunto de API: ExcelApi 1.7 ]

worksheetId

Obtém a ID da planilha na qual os dados foram alterados.

worksheetId: string;

Valor da propriedade

string

Comentários

[ Conjunto de API: ExcelApi 1.7 ]

Detalhes do método

getRange(ctx)

Obtém o intervalo que representa a área alterada de uma planilha específica.

[ Conjunto de API: ExcelApi 1.8 ]

getRange(ctx: Excel.RequestContext): Excel.Range;

Parâmetros

Retornos

getRangeOrNullObject(ctx)

Obtém o intervalo que representa a área alterada de uma planilha específica. Pode retornar o objeto null.

[ Conjunto de API: ExcelApi 1.8 ]

getRangeOrNullObject(ctx: Excel.RequestContext): Excel.Range;

Parâmetros

Retornos