The exportAs() method exports the monthly calendar as an image or Excel spreadsheet.
Declaration
DayPilot.Month.exportAs(format[, options]);Parameters
format("svg"|"png"|"jpeg"|"xlsx") - output formatoptions.area("viewport"|"full"|"range") - exported area; defaults to"viewport"options.dateFrom- start date (applies only toarea: "range")options.dateTo- end date (applies only toarea: "range")options.quality- quality of the output JPEG image (applies only toformat: "jpeg"); defaults to0.92options.scale- output scale factor; defaults to1(use2for 200% magnification)
Excel Export
Provide the ExcelJS library through the exceljs configuration property. For "xlsx", area: "range" exports complete displayed weeks intersecting the half-open interval [dateFrom, dateTo). It respects the configured week start and hidden weekends and does not create weeks outside the loaded grid. "full" and "viewport" export the full loaded grid.
The XLSX result supports download(filename) and toBlobAsync(): Promise<Blob>. See Month Excel Export.
Return Value
Returns a DayPilot.Export object that provides the following methods:
toElement()- returns a DOM element with the image (<svg>or<img>)toHtml()- returns the image element as HTMLtoDataUri()- returns a data URI string (SVG or image data)toBlob()- returns a Blob objectdownload(filename)- forces download of the imageprint()- prints the exported image using the browser print dialog
Notes
Use options.area to export the current viewport, the full calendar, or a custom date range. When area is set to "range", you need to specify options.dateFrom and options.dateTo.
The quality option only affects JPEG output, and scale controls the size of the generated image.
JavaScript
const image = dp.exportAs("png", {
area: "full",
scale: 2
});
image.download("month.png");Angular
Use a template reference and ViewChild in an existing component. Invoke exportImage() from a button after initialization.
<daypilot-month [config]="config" #month></daypilot-month>@ViewChild("month") month!: DayPilotMonthComponent;
config: DayPilot.MonthConfig = {};
exportImage() {
this.month.control.exportAs("png", {area: "full", scale: 2}).download("month.png");
}React
const month = useRef(null);
function exportImage() {
month.current.exportAs("png", {area: "full", scale: 2}).download("month.png");
}
<DayPilotMonth
controlRef={control => { month.current = control; }}
/>Vue
<script setup>
import {ref} from "vue";
const month = ref(null);
function exportImage() {
month.value.control.exportAs("png", {area: "full", scale: 2}).download("month.png");
}
</script>
<template>
<DayPilotMonth ref="month" />
</template>Keep the component’s existing date, data and layout options. Angular imports ViewChild and the DayPilot component type; React imports useRef. Vue uses the DayPilot component already registered or imported by the application.
Bitmap Export Errors
PNG and JPEG export can throw an error with name: "DayPilot.ExportError" and code: "BITMAP_EXPORT_FAILED" if the bitmap cannot be created or encoded. This is a structured error object, not a public constructor.
stage:"dimensions","allocation","drawing"or"encoding"format: output MIME typewidth,height,scale: requested logical dimensions and scalepixelWidth,pixelHeight: requested bitmap dimensionssurface:"main"or"group";surfaceWidthandsurfaceHeight: dimensions of the failed surfacecause: optional underlying error
Native canvas SecurityError exceptions keep their original identity. Image and font loading must be handled separately. The exporter does not automatically reduce scale or paginate a large image; choose a smaller area or scale when appropriate.
See Also
Availability
Availability of this API item in DayPilot editions:
| Product | Lite | Pro |
|---|---|---|
| DayPilot for JavaScript |
DayPilot