Exporting in JavaScript Scheduler
The Scheduler supports exporting appointments to Excel (.xlsx or .csv) and ICS files on the client. This topic explains how to implement exporting and importing features.
Excel Exporting
Use the exportToExcel method to export Scheduler events to an Excel file. By default, it exports the fields specified in the Scheduler’s eventSettings.
Before using the Excel exporting functionality, you need to import and inject the
ExcelExportmodule from the@syncfusion/ej2-schedulepackage using theInjectmethod of Scheduler.
Exporting with custom fields
By default, Scheduler exports all default event fields mapped through the eventSettings property. To limit the number of fields in the exported Excel file, you can export only custom fields of the event data. Define the required fields through the eventSettings interface and pass it as an argument to the exportToExcel method. For example: ['Id', 'Subject', 'StartTime', 'EndTime', 'Location'].
Exporting individual occurrences of a recurring series
By default, the Scheduler exports recurring events as a single record by exporting only the parent recurrence into the Excel file. To export each individual occurrence of a recurring series as separate records, set the includeOccurrences option to true in the ExportOptions and pass it to exportToExcel. The default value for includeOccurrences is false.
Exporting custom event data
By default, the entire event collection bound to the Scheduler is exported as an Excel file. To export only specific events or a custom event collection, pass the custom data collection as a parameter to the exportToExcel method through the customData option of the ExportOptions interface.
By default, the event data is taken from the Scheduler dataSource.
Customizing column header with custom fields exporting
To customize the header of custom fields during export, use the fieldsInfo option through the ExportFieldInfo interface and pass it as an argument to the exportToExcel method.
Export with custom file name
By default, the Scheduler downloads the exported Excel file with the name Schedule.xlsx. To export the Excel file with a custom file name, define the desired fileName through the ExportOptions interface and pass it as an argument to the exportToExcel method.
Excel file formats
By default, the Scheduler exports event data to an Excel file in the .xlsx format. You can also export the Scheduler data in either .xlsx or .csv formats by defining the exportType option as either csv or xlsx through the ExportOptions interface. The default exportType is xlsx.
Custom separator in CSV
The Scheduler exports the event data to CSV format with , as separator. You can change separator by setting separator property in ExportOptions.
How to customize the Excel sheet before exporting
Use the excelExport event to customize the exported workbook and formatting before export.
With the excelExport event you can:
- Adjust the formatting: Apply styles such as font, size, color, and cell formatting.
- Customize headers and footers: Modify header and footer content for the exported sheet.
-
Cancel the export: Cancel the export by setting the
cancelproperty totrue.
Here’s an example of adding a custom header and footer to an Excel sheet using the excelExport event.
Exporting calendar events as ICS file
You can export Scheduler events to a calendar (.ics) file format, which can be opened in other default calendars such as Google or Outlook. To export Scheduler events to an ICS file, first import the ICalendarExport module from the @syncfusion/ej2-schedule package and then inject it using the Schedule.Inject(ICalendarExport) method.
The following code example shows how the Scheduler events are exported to a calendar (.ics) file by making use of the exportToICalendar public method.
Exporting calendar with custom file name
By default, the calendar is exported with a file name Calendar.ics. To change this file name on export, pass the custom string value as fileName to the method argument so as to get the file downloaded with this provided name.
The following example downloads the iCal file with a name ScheduleEvents.ics.
Import events from other calendars
Events from external calendars (ICS files) can be imported into Scheduler using the importICalendar method. This method accepts the blob object of an .ics file to be imported as a mandatory argument.
To import an ICS file containing events into Scheduler, first import the
ICalendarImportmodule from the@syncfusion/ej2-schedulepackage and then inject it using theSchedule.Inject(ICalendarImport)method.
The following example shows how to import an ICS file into Scheduler, using the importICalendar method.
How to print the Scheduler element
Use the print client-side method to print the Scheduler element. The method can be used without options or with a set of print options.
To print the Scheduler, import the Print module from @syncfusion/ej2-schedule and inject it using Schedule.Inject(Print).
Using print method without options
Use the print method without options to print the current view. The following example shows how to print the Scheduler using print without options.
Using a print method with options
You can print the Scheduler using the print method by passing print options. The following example shows how to print the Scheduler with options.
How to customize the print layout
The beforePrint event lets you customize the print layout without altering the Scheduler’s data. It provides the HTML element used for printing and lets you cancel the print by setting cancel to true.
Key customization examples:
- Custom header and footer: Add header/footer content to the print layout.
- Control print output: Fine-tune which elements appear in the printed output.
Here’s an example of adding a custom header and footer to the print layout using beforePrint.
Refer to our JavaScript Scheduler feature tour page for comprehensive feature demonstrations. You can also explore the JavaScript Scheduler example to learn how to present and manipulate data.