Export Excel files using client-side processing in Angular Spreadsheet

20 Nov 20266 minutes to read

The Angular Spreadsheet Editor component uses a client-side workflow to generate workbook files directly in the browser without sending data to a Save service. When the allowSave property is enabled by default and the saveUrl property is not configured, the Spreadsheet uses its integrated client-side file-generation functionality, which internally uses the @syncfusion/ej2-xlsx library.

Advantages of Client-Side Export

Client-side export provides several key advantages over server-side processing:

  • No Server Dependency: Process Excel files directly in the browser without requiring server endpoints.
  • Reduced Network Overhead: Avoid uploading workbook data to a server and waiting for server-side file processing.
  • Reduced Infrastructure Costs: Eliminate the need to deploy and maintain server-side file-processing infrastructure.
  • Enhanced Privacy: Keep workbook data within the browser during export instead of sending it to a file-processing service.
  • Offline Capability: Generate and download Excel files without an internet connection.

How client-side export works

For save processing, the Spreadsheet component maps its in-memory workbook model-including cell data, formulas, styles, formatting, merged cells, and worksheet settings-directly into the @syncfusion/ej2-xlsx workbook object model. The ej2-xlsx library then compiles and generates the fully formatted Excel (.xlsx) binary file directly in the browser without any server dependency.

Supported formats

Client-side export currently supports:

  • Microsoft Excel Workbook (.xlsx)

Configure client-side export

Unlike server-side processing, the saveUrl must be omitted for client-side processing since there is no server-side request. This approach provides enhanced privacy, improved performance, and reduced infrastructure costs.

import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent, SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [SpreadsheetAllModule],
  template: `<ejs-spreadsheet #spreadsheet ></ejs-spreadsheet>`
  // Note: saveUrl is omitted for client-side export
})
export class AppComponent {
  @ViewChild('spreadsheet') public spreadsheet!: SpreadsheetComponent;

}

With this configuration, the Spreadsheet will generate Excel files directly in the browser without requiring server communication.

Saving Excel files programmatically

To save Excel files programmatically in the Spreadsheet, you can use the save method of the Spreadsheet component. When calling this method with client-side processing, the Spreadsheet generates the file directly in the browser and triggers browser download.

import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent, SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [SpreadsheetAllModule],
  template: `<ejs-spreadsheet #spreadsheet ></ejs-spreadsheet>
<button type="button" (click)="save()">Save</button>`
})
export class AppComponent {
  @ViewChild('spreadsheet') public spreadsheet!: SpreadsheetComponent;
  public save(): void {
    this.spreadsheet.save({ fileName: 'Worksheet', saveType: 'Xlsx' });
  }
}

Saving Excel files as Blob data

To save an Excel file as blob data, you need to set needBlobData to true and isFullPost to false in the beforeSave event. Subsequently, you will receive the spreadsheet data as a blob in the saveComplete event.

import { NgModule, ViewChild } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { BeforeSaveEventArgs, SaveCompleteEventArgs, SpreadsheetAllModule, SpreadsheetComponent, created } from '@syncfusion/ej2-angular-spreadsheet'
import { Component } from '@angular/core';
import { getDefaultData } from './datasource';

@Component({
  imports: [

    SpreadsheetAllModule
  ],
  standalone: true,
  selector: 'app-container',
  template: `<div class="control-section">
  <ejs-spreadsheet #spreadsheet (beforeSave)="beforeSave($event)" (saveComplete)="saveComplete($event)">
        <e-sheets>
            <e-sheet name="Car Sales Report">
                <e-ranges>
                    <e-range [dataSource]="data"></e-range>
                </e-ranges>
                <e-columns>
                    <e-column [width]=180></e-column>
                    <e-column [width]=130></e-column>
                    <e-column [width]=130></e-column>
                    <e-column [width]=180></e-column>
                    <e-column [width]=130></e-column>
                    <e-column [width]=120></e-column>
                </e-columns>
            </e-sheet>
        </e-sheets>
    </ejs-spreadsheet>
</div>`
})
export class AppComponent {
  constructor() {

  }
  
  @ViewChild('spreadsheet')
  
  public spreadsheetObj!: SpreadsheetComponent;
  public data: Object[] = getDefaultData();

    beforeSave(args: BeforeSaveEventArgs): void {
        args.needBlobData = true; // To trigger the saveComplete event.
        args.isFullPost = false; // Get the spreadsheet data as blob data in the saveComplete event.
    };
    saveComplete(args: SaveCompleteEventArgs): void {
        // To obtain the Blob data.
        console.log("Spreadsheet BlobData: ", args.blobData)
    };
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app';
import 'zone.js'
bootstrapApplication(AppComponent)
  .catch((err) => console.error(err));

Considerations

  1. Format Limitation: Client-side export currently supports XLSX format only
  2. No saveUrl Required: saveUrl must not be configured for client-side export

See also