exports data from the Gantt chart to an Excel document
export | object | optional, an object with export settings (see the details) |
gantt.exportToExcel({
name:"document.xlsx",
columns:[
{ id:"text", header:"Title", width:150 },
{ id:"start_date", header:"Start date", width:250, type:"date" }
],
server:"https://myapp.com/myexport/gantt",
callback: function(res){
alert(res.url);
},
visual:true,
cellColors:true,
date_format: "dddd d, mmmm yyyy"
});
This method is defined in the export extension, so you need to activate the export_api plugin. Read the details in the Export/Import for Excel, Export to iCal article.
If you use the Gantt version older than 8.0, you need to include the https://export.dhtmlx.com/gantt/api.js on your page to enable the online export service, e.g.:
<script src="codebase/dhtmlxgantt.js"></script>
<script src="https://export.dhtmlx.com/gantt/api.js"></script>
The exportToExcel() method takes as a parameter an object with several properties (all the properties are optional):
Format code | Output |
d | 9 |
dd | 09 |
ddd | Mon |
dddd | Monday |
mm | 01 |
mmm | Jan |
mmmm | January |
mmmmm | J |
yy | 12 |
yyyy | 2021 |
mm/dd/yyyy | 01/09/2021 |
m/d/y | 1/9/21 |
ddd, mmm d | Mon, Jan 9 |
mm/dd/yyyy h:mm AM/PM | 01/09/2021 6:20 PM |
dd/mm/yyyy hh:mm:ss | 09/01/2012 16:20:00 |
The Export module expects the start_date and end_date columns to have the Date type and the duration column to have the number type.
In case of applying custom templates, it is necessary either to return a value of the expected type or to define a different value in the name property of the column configuration. For instance:
gantt.config.columns = [
...
{name: "start_date", align: "center", width: 100, resize: true,
editor: start_dateEditor},
{name: "end_date", align: "center", width: 100, resize: true,
editor: end_dateEditor},
{name: "duration_formatted", align: "center", width: 40, resize: true,
editor: durationEditor,
template: function(task){ return formatter.format(task.duration_formatted); }
},
...
];
Otherwise, the Gantt data won't be exported. Check the related example.