Excel export in Vue Gantt component
16 Mar 20233 minutes to read
Gantt supports client-side exporting, which allows you to export its data to the Excel and CSV formats. Use the excelExport
and csvExport
methods for exporting. To enable Excel export in the Gantt, set the allowExcelExport
to true.
To export data to Excel and CSV, inject the ExcelExport
module in Gantt.
<template>
<div>
<ejs-gantt ref='gantt' id="GanttContainer" :dataSource="data" :taskFields="taskFields" :toolbar="toolbar" :toolbarClick="toolbarClick" :allowExcelExport='true' :height="height"></ejs-gantt>
</div>
</template>
<script>
import Vue from "vue";
import { GanttPlugin, Toolbar, ExcelExport, Selection } from "@syncfusion/ej2-vue-gantt";
import { ClickEventArgs } from '@syncfusion/ej2-navigations';
import { ganttData } from './data-source.js';
Vue.use(GanttPlugin);
export default {
data: function() {
return{
data: ganttData,
height:'450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
toolbar: ['ExcelExport', 'CsvExport'],
toolbarClick: (args: ClickEventArgs) => {
if (args.item.id === 'GanttContainer_excelexport') {
var ganttObj = document.getElementById('GanttContainer').ej2_instances[0];
ganttObj.excelExport();
} else if(args.item.id === 'GanttContainer_csvexport') {
var ganttObj = document.getElementById('GanttContainer').ej2_instances[0];
ganttObj.csvExport();
}
},
};
},
provide: {
gantt: [Toolbar, ExcelExport]
}
};
</script>