Spreadsheet API
Use Office.cell(iframe) for an iframe that opened a Spreadsheet document. The module identifier is cell; the
product name is Spreadsheet.
First complete the distribution, import map, and HTTP server setup in the Editor SDK quickstart.
Open this document type in the office-frame iframe. Use the JavaScript blocks below in order in the same module
script. Write examples change the document, so run them on a sample or copy.
Object model
The root handle is Cell.Workbook. Object types in the current catalog: Worksheet, Range, Chart, Table, and
Filter.
Sheets, tables, and charts
This example overwrites A21:B23 on the first sheet and creates a table. Use a range without existing data and do not
create the table repeatedly in the same range. To select a sheet by name, use its actual name from getSheetList().
import { Office } from "@thinkfree.dev/tfo-sdk";
const iframe = document.querySelector("#office-frame");
const cell = Office.cell(iframe);
await cell.whenReady();
const wb = cell.getWorkbook();
console.log(await wb.getSheetList()); // [{ name, active }, …]
const ws = await wb.getWorksheet(0); // one round trip; the sheet is resolved here
await ws.getRange("A21:B23").setValues([["Name", "Value"], ["a", 1], ["b", 2]]);
await ws.addTable("A21:B23", true); // header row = true
const info = await ws.getSheetInfo(); // usedRange and selection as A1 strings
Errors
If a sheet or a path element does not exist, the call that resolves it rejects with SDKError and error.data
carries the structured response. Branch on the code instead of parsing the message:
import { SDKError } from "@thinkfree.dev/tfo-sdk";
try {
const ws = await wb.getWorksheet("Nope"); // rejects here for an unknown sheet
await ws.getRange("A1").getValues();
} catch (error) {
if (error instanceof SDKError && error.data?.success === false) {
console.warn(error.data.error.code); // e.g. "SHEET_NOT_FOUND"
}
}
See Document tools and error handling for the full error table.
API reference
Every object type available on Spreadsheet handles in the current SDK build has its own reference page, generated
from the SDK type definitions: a method summary table, then each method's TypeScript signature, parameters, and return
value. Navigation methods (getRange, getChart, getFilter, getTable, getObjectById, getDefinedName)
return a child handle synchronously; every other method returns a Promise. Pick an object type
below or open it from the sidebar.
Spreadsheet · 6 object types · 156 methods · namespace Cell. This reference is generated from the API document artifact (sdk-api-doc.html) produced with the SDK build. Descriptions are the editor's API comments as published. Pin the SDK and Office versions together and regenerate when either changes.
| Object type | Methods | Obtained from |
|---|---|---|
Cell.Workbook | 13 | app.getDocument() / app.getWorkbook() |
Cell.Worksheet | 30 | Workbook.getWorksheet() |
Cell.Range | 76 | Worksheet.getRange(), Worksheet.getSelection(), Worksheet.getUsedRange(), … |
Cell.Chart | 22 | Workbook.getObjectById(), Worksheet.addChart(), Worksheet.getChart() |
Cell.Table | 9 | Workbook.getTable(), Worksheet.addTable() |
Cell.Filter | 6 | Worksheet.getFilter(), Table.getFilter() |
Constant members are listed on the Cell.* page.