The Spreadsheet Editor is in edit mode by default. In edit mode, users can modify and interact with spreadsheets using familiar, grid-based interactions similar to Excel. Users can interact with cells, including:
Cell formatting: Modify text size and color, fonts, border styles, cell colors, border colors, and text styling for bold, italics, underlining, and strikethrough.
Formula and function support: Execute standard mathematical operations, statistical calculations, date/time functions, and other common formulas.
Dynamic data manipulation: Easily add, edit, and delete rows and columns. Seamlessly cut, copy, and paste data.
Cell adjustments: Merge cells and preserve formatting.
File support: Open files in XLSX, XLS, and CSV formats. Export as XLSX or PDF.
Edit mode is ideal for tasks like data entry, adjusting cell styles, and organizing sheet content.
Users can click the dropdown on the Mode flyout in the upper-right corner of the Spreadsheet Editor UI to switch between Viewing and Editing mode.
For programmatic changes, you could, for example, build a reporting dashboard that imports sales data into a spreadsheet. After the data is loaded, the app programmatically applies formatting - bold headers, alternating row colors, and column width adjustments- improving readability without requiring users to manually style the sheet. You'd use the CellRange constructor to create an instance, then apply styling with the Sheet.setCellRangeStyle API.
A workbook is the top-level container for all spreadsheet data. It includes multiple sheets and supports operations such as getting, creating, removing, or switching sheets. Users can interact with the workbook through the UI or programmatically using the Workbook class. The workbook instance can be retrieved with the SpreadsheetEditorManager.getWorkbookAPI shown in the following sample.
Sheets are tabbed pages within a workbook, each with its own grid of cells, or rows of cells. They help organize data into separate sections, like months, categories, or teams. Only the active sheet is visible and editable at a time. Sheets can also be managed programmatically for dynamic workflows.
A sheet instance can be retrieved from a workbook instance using the Workbook.getSheetAPI or Workbook.getSheetAtAPI.
Use the Sheet.setColumnWidthInPixelAPI and Sheet.setRowHeightInPixelAPI to resize columns and rows, respectively. The following code sample sets the first column height and row width to 200px.
Cells are the basic building blocks of a spreadsheet, used to enter data, text, or formulas. Each is identified by its row and column (e.g., B2) and can be styled, merged, or formatted. Users can edit cells directly through the formula bar or programmatically via an API.
You could, for example, develop a budgeting application that programmatically reads XLSX files and applies a light-red background color to cells that don't match their expected format (e.g., invalid format, missing values). You'd use the Cell.setStyle API to change the background color of a specific cell.
Access a single cell
The following code sample shows how to access a cell programmatically using the Sheet.getCellAtAPI and alternatively the Row.getCellAtAPI.
The following code sample shows how to set the value of a cell using different types of values, including strings, booleans, numbers, and dates. See the Cell class documentation for a detailed look at the available APIs.
The following code sample shows how to apply various styles to the actively selected cells using the SpreadsheetEditorManager.setSelectedCellsStyleAPI.
A cell range is a collection of one or more cells in a rectangular grouping. They are defined by their first and last row and column. Use cell ranges when you want to interact with groups of cells. See CellRange class documentation.
Create a cell range
Cell ranges are created via a constructor. They are defined either by a string representation (e.g., A1:B5) or by an object specifying the first and last row and column indices.
8 // Two different ways of creating a cell range for A1:B5.
9 const cellRange = new SpreadsheetEditor.CellRange('A1:B5');
10 const cellRange2 = new SpreadsheetEditor.CellRange({
11 firstRow: 0,
12 firstColumn: 0,
13 lastRow: 4,
14 lastColumn: 1
15 });
16
17 // These will both log out 'A1:B5'.
18 console.log(cellRange.rangeDisplayValue);
19 console.log(cellRange2.rangeDisplayValue);
20 });
21 });
Select a cell range
Use the SpreadsheetEditorManager.selectCellRangeAPI to programmatically select one or more cells. Calling this API will automatically scroll the viewer to the selected cell range. The following code sample shows how to select the cell range A1:B5.
Use the Sheet.setCellRangeStyleAPI and the Sheet.setCellRangeBorderAPI to programmatically apply styling and borders to a cell range, respectively. Please note that calling these APIs will overwrite the existing styling. The following code sample shows how to apply a red background with dotted borders.
19 const cellRange = new SpreadsheetEditor.CellRange('A1:F1');
20 sheet.setCellRangeStyle(cellRange, style);
21 sheet.setCellRangeBorder(cellRange, border);
22 });
23 });
Formula bar
The formula bar is where users can view and edit the contents of active cells. It serves as a single-line input field that supports both plain values and formulas (e.g., =A1+B1). When a cell is selected, its content automatically appears in the formula bar for quick inspection or modification. We have a full list of supported formulas you can review to see which best support your needs.
Set a cell formula
The following code sample shows how to programmatically set a formula on a specific cell using the Cell.setFormulaAPI.
Images are stored individually in each sheet. You can read, add, and remove images from any sheet. The following image formats are supported:
BMP
GIF
JPEG
PNG
Get images
Use the Sheet.getImageAPI to get images from a specific sheet. With this, you can access an image's size, position, and original source. Refer to the SpreadsheetEditorImage class to see all available properties.
Use the Sheet.addImageAPI to add images to a specific sheet. Images can be added by passing a relative path, HTTP(S) URL, or Base64-encoded data URL. If position and size are not provided, the image is placed in the top-left corner with a default size of 250x250 pixels.
Use the Sheet.removeImageAPI to remove images from a specific sheet. The following code sample shows how to remove the first image from the first sheet.