Spreadsheet Editor - Edit Mode

Requirements
View Demo

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.

Spreadsheet Editor must be purchased as an add-on to your Web SDK subscription.

Screenshot of the Apryse SDK Spreadsheet Editor with labeled callouts highlighting UI features such as clipboard operations, a formula bar, cell fonts, cell styling, and sheet tabs.

See our interactive Spreadsheet Editor demo.

Workbook

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.getWorkbook API shown in the following sample.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const workbook = spreadsheetEditorManager.getWorkbook();
9 });
10 });

Get a sheet

The following code sample shows how to get a sheet with the 0-based index using the Workbook.getSheetAt API after the editor is initialized.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const workbook = spreadsheetEditorManager.getWorkbook();
9 const sheet = workbook.getSheetAt(0);
10 });
11 });

A sheet can also be retrieved by its name using the Workbook.getSheet API.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const workbook = spreadsheetEditorManager.getWorkbook();
9 const sheet = workbook.getSheet('Invoice');
10 });
11 });

Create sheets

The following code sample creates a new sheet using the Workbook.createSheet API after the editor is initialized.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 workbook.createSheet('New Sheet');
11 });
12 });

Remove sheets

The following code sample removes a sheet using the Workbook.removeSheet API.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 workbook.removeSheet('New Sheet');
11 });
12 });

Set active sheet

The following code sample sets the last sheet of the workbook to be active using the Workbook.setActiveSheet API and Workbook.sheetCount property.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const workbook = spreadsheetEditorManager.getWorkbook();
9 workbook.setActiveSheet(workbook.sheetCount - 1);
10 });
11 });

Sheets

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.getSheet API or Workbook.getSheetAt API.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const workbook = spreadsheetEditorManager.getWorkbook();
9 const sheet = workbook.getSheet('Sheet1');
10
11 // Alternatively, using the zero-based index API, you
12 // can retrieve the first sheet in a workbook.
13 const firstSheet = workbook.getSheetAt(0);
14 });
15 });

Access rows

See the Row documentation for available APIs. The following code sample gets the first row from a sheet in a workbook.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const workbook = spreadsheetEditorManager.getWorkbook();
9 const sheet = workbook.getSheetAt(0);
10 let row = sheet.getRowAt(0);
11
12 // Alternatively, you can chain the methods together.
13 row = workbook.getSheetAt(0).getRowAt(0);
14 console.log(row);
15 });
16 });

Add rows and columns

The following code sample shows how to add rows and columns to a sheet.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const sheet = workbook.getSheetAt(0);
11
12 const count = 5;
13 const startIndex = 0;
14
15 // Inserts 5 rows and columns at the
16 // first row and column of a sheet.
17 sheet.createRows(startIndex, count);
18 sheet.createColumns(startIndex, count);
19 });
20 });

Remove rows and columns

The following code sample shows how to remove rows and columns from a sheet.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const sheet = workbook.getSheetAt(0);
11
12 const count = 5;
13 const startIndex = 0;
14
15 // Removes 5 rows and columns starting
16 // from the top-left (0 index) of the sheet.
17 sheet.removeRows(startIndex, count);
18 sheet.removeColumns(startIndex, count);
19 });
20 });

Resize rows and columns

Use the Sheet.setColumnWidthInPixel API and Sheet.setRowHeightInPixel API to resize columns and rows, respectively. The following code sample sets the first column height and row width to 200px.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const sheet = workbook.getSheetAt(0);
11
12 const rowIndex = 0;
13 const columnIndex = 0;
14 const sizeInPixels = 200;
15
16 sheet.setRowHeightInPixel(rowIndex, sizeInPixels);
17 sheet.setColumnWidthInPixel(columnIndex, sizeInPixels);
18 });
19 });

Cells

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.getCellAt API and alternatively the Row.getCellAt API.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const workbook = spreadsheetEditorManager.getWorkbook();
9 const sheet = workbook.getSheetAt(0);
10 let cell = sheet.getRowAt(0).getCellAt(0);
11
12 // Alternatively, you can call the Sheet.getCellAt API directly.
13 cell = sheet.getCellAt(0, 0);
14 console.log(cell);
15 });
16 });

Access currently selected cells

The following code sample demonstrates how to programmatically access the currently selected cells using the following SpreadsheetEditorManager APIs:

  • getSelectedCells API to retrieve a Cell[]
  • getSelectedCellRange API to retrieve a CellRange

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const cells = spreadsheetEditorManager.getSelectedCells();
9 const cellRange = spreadsheetEditorManager.getSelectedCellRange();
10 });
11 });

Set a cell value

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.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const cell = workbook
11 .getSheetAt(0)
12 .getRowAt(0)
13 .getCellAt(0);
14
15 // cell.setBooleanValue(false);
16 // cell.setFormula('=SUM(5, 5)');
17 // cell.setStringValue('Hello World');
18 // cell.setDateValue('2025-01-01 09:00:00');
19 cell.setNumericValue(100);
20 console.log(cell);
21 });
22 });

Apply styles to a cell

The following code sample shows how to apply various styles to an individual cell using the Cell.setStyle API and Workbook.createFont API.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const cell = workbook
11 .getSheetAt(0)
12 .getRowAt(0)
13 .getCellAt(0);
14
15 const font = workbook.createFont({
16 fontFace: 'Times New Roman',
17 pointSize: 12,
18 color: 'red',
19 bold: true,
20 italic: true,
21 underline: true
22 });
23
24 const cellStyle = cell.getStyle();
25 cellStyle.font = font;
26 cellStyle.horizontalAlignment = SpreadsheetEditor.Types.HorizontalAlignment.CENTER;
27 cellStyle.verticalAlignment = SpreadsheetEditor.Types.VerticalAlignment.CENTER;
28 cellStyle.backgroundColor = 'lightgreen';
29 cellStyle.wrapText = SpreadsheetEditor.Types.TextWrap.OVERFLOW;
30
31 cell.setStyle(cellStyle);
32 });
33 });

Apply styles to selected cells

The following code sample shows how to apply various styles to the actively selected cells using the SpreadsheetEditorManager.setSelectedCellsStyle API.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9
10 const styleObject = {
11 verticalAlignment: SpreadsheetEditor.Types.VerticalAlignment.CENTER,
12 horizontalAlignment: SpreadsheetEditor.Types.HorizontalAlignment.CENTER,
13 font: {
14 fontFace: 'Times New Roman',
15 pointSize: 12,
16 color: '#000000',
17 bold: true,
18 italic: true,
19 underline: true,
20 strikeout: false
21 }
22 };
23
24 spreadsheetEditorManager.setSelectedCellsStyle(styleObject);
25 });
26 });

Cell ranges

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.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
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.selectCellRange API 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.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const cellRange = new SpreadsheetEditor.CellRange('A1:B5');
9 spreadsheetEditorManager.selectCellRange(cellRange);
10 });
11 });

Get currently selected cell range

Use the SpreadsheetEditorManager.getSelectedCellRange API to get a CellRange representation of the currently selected cells.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 const cellRange = spreadsheetEditorManager.getSelectedCellRange();
9 });
10 });

Style a cell range

Use the Sheet.setCellRangeStyle API and the Sheet.setCellRangeBorder API 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.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const sheet = workbook.getSheetAt(0);
11
12 const style = workbook.createCellStyle({ backgroundColor: 'red' });
13 const border = {
14 color: 'black',
15 style: SpreadsheetEditor.Types.BorderStyle.DOTTED,
16 type: SpreadsheetEditor.Types.RangeBorderType.OUTSIDE,
17 };
18
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.setFormula API.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const cell = workbook
11 .getSheetAt(0)
12 .getRowAt(0)
13 .getCellAt(0);
14
15 cell.setFormula('=SUM(5, 95)');
16 });
17 });

Images

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.getImage API 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.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const sheet = workbook.getSheetAt(0);
11
12 if (sheet.imagesCount > 0) {
13 const image = sheet.getImage(0);
14 console.log(image);
15 }
16 });
17 });

Add images

Use the Sheet.addImage API 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.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, async () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const sheet = workbook.getSheetAt(0);
11
12 await sheet.addImage('./path/to/relative/image.png');
13 await sheet.addImage('https://www.example.com/image.png', {
14 x: 100,
15 y: 100,
16 width: 500,
17 height: 300
18 });
19 });
20 });

Remove images

Use the Sheet.removeImage API to remove images from a specific sheet. The following code sample shows how to remove the first image from the first sheet.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
5 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const workbook = spreadsheetEditorManager.getWorkbook();
10 const sheet = workbook.getSheetAt(0);
11
12 if (sheet.imagesCount > 0) {
13 sheet.removeImage(0);
14 }
15 });
16 });

Undo and redo

The Spreadsheet Editor supports undo and redo for a variety of actions, such as:

  • Editing cell values.
  • Changing cell styles.
  • Adding or removing sheets.
  • Resizing columns and rows.
  • Moving and resizing charts.

The following code sample shows how to detect if there are actions that can be undone or redone.

JavaScript

1WebViewer(...)
2 .then(instance => {
3 const { documentViewer, SpreadsheetEditor } = instance.Core;
4 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
5 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
6
7 spreadsheetEditorManager.addEventListener(SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY, async () => {
8 spreadsheetEditorManager.setEditMode(SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING);
9 const spreadsheetEditorHistoryManager = spreadsheetEditorManager.getSpreadsheetEditorHistoryManager();
10
11 if (spreadsheetEditorHistoryManager.canUndo()) {
12 await spreadsheetEditorHistoryManager.undo();
13 }
14
15 if (spreadsheetEditorHistoryManager.canRedo()) {
16 await spreasdheetEditorHistoryManager.redo();
17 }
18 });
19 });

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales