Spreadsheet Editor Showcase Demo Sample Code

Requirements
View Demo

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

Learn more about Web SDK and Spreadsheet Editor.

Implementation steps

To add XLSX file viewing and editing capability with WebViewer:

Step 1: Follow get started in your preferred web stack for WebViewer
Step 2: Implement WebViewer using iFrame
Step 3: Add the ES6 JavaScript sample code provided in this guide

Once you generate your license key, it will automatically be included in your sample code below.

License Key

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

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales