Export Excel files using client-side processing in Vue Spreadsheet
25 Nov 20268 minutes to read
The Vue 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.
<template>
<ejs-spreadsheet ref="spreadsheet" />
</template>
<script setup>
import { ref } from 'vue';
import { SpreadsheetComponent as EjsSpreadsheet } from '@syncfusion/ej2-vue-spreadsheet';
const spreadsheet = ref(null);
</script>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.
<template>
<ejs-spreadsheet ref="spreadsheet" />
<button type="button" @click="save">Save</button>
</template>
<script setup>
import { ref } from 'vue';
import { SpreadsheetComponent as EjsSpreadsheet } from '@syncfusion/ej2-vue-spreadsheet';
const spreadsheet = ref(null);
const save = () => {
spreadsheet.value.save({ fileName: 'Worksheet', saveType: 'Xlsx' });
};
</script>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.
<template>
<div>
<ejs-spreadsheet ref="spreadsheet" :beforeSave="beforeSave" :saveComplete="saveComplete">
<e-sheets>
<e-sheet name="Car Sales Report">
<e-ranges>
<e-range :dataSource="dataSource"></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=120></e-column>
<e-column :width=130></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>
</div>
</template>
<script setup>
import { ref } from "vue";
import { SpreadsheetComponent as EjsSpreadsheet, SheetsDirective as ESheets, SheetDirective as ESheet, RangesDirective as ERanges, RangeDirective as ERange, ColumnsDirective as EColumns, ColumnDirective as EColumn } from "@syncfusion/ej2-vue-spreadsheet";
import { data } from './data.js';
const spreadsheet = ref(null);
const dataSource = data;
const beforeSave = function (args) {
args.needBlobData = true; // To trigger the saveComplete event.
args.isFullPost = false; // Get the spreadsheet data as blob data in the saveComplete event.
}
const saveComplete = function (args) {
// To obtain blob data.
console.log("Spreadsheet BlobData: ", args.blobData);
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-tailwind3-theme/styles/spreadsheet/index.css';
.custom-btn {
margin-bottom: 10px;
}
</style><template>
<div>
<ejs-spreadsheet ref="spreadsheet" :beforeSave="beforeSave" :saveComplete="saveComplete">
<e-sheets>
<e-sheet name="Car Sales Report">
<e-ranges>
<e-range :dataSource="dataSource"></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=120></e-column>
<e-column :width=130></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>
</div>
</template>
<script>
import { SpreadsheetComponent, SheetsDirective, SheetDirective, RangesDirective, RangeDirective, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-vue-spreadsheet";
import { data } from './data.js';
export default {
name: "App",
components: {
"ejs-spreadsheet": SpreadsheetComponent,
"e-sheets": SheetsDirective,
"e-sheet": SheetDirective,
"e-ranges": RangesDirective,
"e-range": RangeDirective,
"e-columns": ColumnsDirective,
"e-column": ColumnDirective
},
data: () => {
return {
dataSource: data
}
},
methods: {
beforeSave: function (args) {
args.needBlobData = true; // To trigger the saveComplete event.
args.isFullPost = false; // Get the spreadsheet data as blob data in the saveComplete event.
},
saveComplete: function (args) {
// To obtain blob data.
console.log("Spreadsheet BlobData: ", args.blobData);
}
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-tailwind3-theme/styles/spreadsheet/index.css';
.custom-btn {
margin-bottom: 10px;
}
</style>Considerations
- Format Limitation: Client-side export currently supports XLSX format only
-
No saveUrl Required:
saveUrlmust not be configured for client-side export