Skip to main content

KEELSTONE_GET_RANGE

Requests the address of the currently selected range in Excel. The taskpane responds immediately with KEELSTONE_RANGE_RESPONSE containing the address string.

Use this to let users point to where they want data written, rather than typing a cell address manually.

Payload

{
type: 'KEELSTONE_GET_RANGE';
}

No additional fields required.

Response: KEELSTONE_RANGE_RESPONSE

{
type: 'KEELSTONE_RANGE_RESPONSE';
address: string; // e.g. "Sheet1!B3" or "Sheet1!A1:D10"
}

The address is the full sheet-qualified address of whatever the user has selected in Excel at the moment the button is pressed.

Example

// LWC: request active selection
handleGetRangeClick() {
window.parent.postMessage({ type: 'KEELSTONE_GET_RANGE' }, '*');
}

// LWC: receive response
connectedCallback() {
this._handler = (event) => {
if (event.data?.type === 'KEELSTONE_RANGE_RESPONSE') {
this.activeRange = event.data.address;
}
};
window.addEventListener('message', this._handler);
}
disconnectedCallback() {
window.removeEventListener('message', this._handler);
}

Then pass this.activeRange as the target in a subsequent KEELSTONE_WRITE:

window.parent.postMessage({
type: 'KEELSTONE_WRITE',
data: myData,
target: this.activeRange, // e.g. "Sheet2!C5"
}, '*');

UX pattern

Pair this with a button that has a map pin or location icon. The user selects a cell in Excel, then clicks the button — the LWC captures the address and displays it so the user knows where their data will land before clicking Run.

<lightning-input type="text" value={activeRange} placeholder="A1"></lightning-input>
<lightning-button-icon
icon-name="utility:location"
variant="border"
title="Get active range from Excel"
onclick={handleGetRangeClick}>
</lightning-button-icon>