Spreadsheet Editor Showcase Demo Code Sample

Easily enable loading, viewing, and editing XLSX files directly in your browser, without server-side dependencies or MS Office installations.

This demo lets you:

  • Upload XLSX files directly to your browser
  • View and edit XSLX files
  • Process XLSX files within a custom app

Implementation steps
To add XLSX file viewing and editing capability with WebViewer:

Step 1: Choose your preferred web stack
Step 2: Download any required modules listed in the Demo Dependencies section below
Step 3: Add the ES6 JavaScript sample code provided in this guide

Demo Dependencies
This sample uses the following:

Want to see a live version of this demo?

Try the Spreadsheet Editor (XSLX) demo

1// ES6 Compliant Syntax
2// GitHub Copilot v1, Claude Sonnet 4 (Preview), 2025-09-15
3// File: showcase-demos/spreadsheet-editor/index.js
4
5import WebViewer from '@pdftron/webviewer';
6
7// Custom File class to hold file metadata (not to be confused with browser's File API)
8class FileMetadata {
9 constructor(options) {
10 this.name = options.name;
11 this.displayName = options.displayName;
12 this.path = options.path;
13 this.extension = options.extension;
14 this.displayExtension = options.displayExtension;
15 this.id = options.id;
16 }
17}
18
19const files = {
20 ANNUAL_FINANCIAL_REPORT: new FileMetadata({
21 name: 'annual_financial_report.xlsx',
22 displayName: 'Annual Financial Report (xlsx)',
23 path: 'https://apryse.s3.us-west-1.amazonaws.com/public/files/samples/annual_financial_report.xlsx',
24 extension: 'xlsx',
25 id: 82,
26 }),
27 INVOICE_TEMPLATE: new FileMetadata({
28 name: 'invoice_template.xlsx',
29 displayName: 'Invoice Template (xlsx)',
30 path: 'https://apryse.s3.us-west-1.amazonaws.com/public/files/samples/invoice_template.xlsx',
31 extension: 'xlsx',
32 displayExtension: 'xlsx',
33 id: 48,
34 }),
35 XLSX_5000_ROWS: new FileMetadata({
36 name: 'file_5000_rows.xlsx',
37 displayName: 'File with 5000 rows (xlsx)',
38 path: 'https://apryse.s3.us-west-1.amazonaws.com/public/files/samples/file_5000_rows.xlsx',
39 extension: 'xlsx',
40 id: 83,
41 }),
42}
43
44const sampleDocuments = [
45 files.ANNUAL_FINANCIAL_REPORT,
46 files.INVOICE_TEMPLATE,
47 files.XLSX_5000_ROWS,
48];
49
50const defaultFile = sampleDocuments[0].path;
51
52// Function to initialize and load the Spreadsheet Editor
53
54function loadSpreadsheetEditor() {
55 const element = document.getElementById('viewer');
56 if (!element) {
57 console.error('Viewer div not found.');
58 return;
59 }
60
61 WebViewer.Iframe({
62 path: '/lib',
63 licenseKey: 'ADD_YOUR_LICENSE_KEY',
64 initialDoc: defaultFile,
65 enableFilePicker: true, // Enable file picker to open files. In WebViewer -> menu icon -> Open File
66 initialMode: WebViewer.Modes.SPREADSHEET_EDITOR,
67 }, element).then(instance => {
68
69 const { documentViewer, SpreadsheetEditor } = instance.Core;
70 const spreadsheetEditorManager = documentViewer.getSpreadsheetEditorManager();
71 const SpreadsheetEditorEvents = SpreadsheetEditor.SpreadsheetEditorManager.Events;
72
73 // Ensure the Spreadsheet Editor Manager is ready and set to editing mode
74 spreadsheetEditorManager.addEventListener(
75 SpreadsheetEditorEvents.SPREADSHEET_EDITOR_READY,
76 () => {
77 spreadsheetEditorManager.setEditMode(
78 SpreadsheetEditor.SpreadsheetEditorEditMode.EDITING
79 );
80 },
81 { once: true }
82 );
83
84 });
85
86 // UI section
87 //
88 // Create a container for all controls (label, dropdown, and buttons)
89 const controlsContainer = document.createElement('div');
90 controlsContainer.className = 'control-container';
91 controlsContainer.id = 'gallery-container';
92 element.insertBefore(controlsContainer, element.firstChild);
93
94 const filesArray = [
95 { name: sampleDocuments[0].displayName, thumbnail: '/showcase-demos/spreadsheet-editor/annual_financial_report.png', url: sampleDocuments[0].path },
96 { name: sampleDocuments[1].displayName, thumbnail: '/showcase-demos/spreadsheet-editor/invoice_template.png', url: sampleDocuments[1].path },
97 { name: sampleDocuments[2].displayName, thumbnail: '/showcase-demos/spreadsheet-editor/file_5000_rows.png', url: sampleDocuments[2].path }
98 ]
99
100 //
101 console.log('gallery-picker.js loaded, GalleryPicker:', window.GalleryPicker);
102 // Dynamically load gallery-picker.js if not already loaded
103 if (!window.GalleryPicker) {
104 const script = document.createElement('script');
105 script.src = '/showcase-demos/spreadsheet-editor/gallery-picker.js';
106 script.onload = function () {
107 console.log('Safe to use GalleryPicker here');
108 GalleryPicker.init('gallery-container', filesArray, (file) => {
109 console.log('Selected file:', file);
110 WebViewer.getInstance().UI.loadDocument(file.url, { filename: file.name, extension: file.extension });
111 });
112 console.log('GalleryPicker.init', GalleryPicker.init);
113
114 };
115 document.head.appendChild(script);
116 }
117
118 if (window.GalleryPicker) {
119 element.insertBefore(controlsContainer, element.firstChild);
120 }
121}
122
123loadSpreadsheetEditor();
124
125
126

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales