export-data
The functionality is available in PRO Edition only
PRODescription
Triggers export of Gantt data to PDF, PNG, Excel, or MS Project XMLThe export-data action allows exporting Gantt data to PDF, PNG, Excel, or MS Project XML formats.
If url is provided, the action sends the current Gantt state to a ready-made server-side export service which generates files in PDF, PNG, XLSX, or MS Project XML (MSPX) formats.
If url is not provided (MS Project XML only), the action exports data using client-side logic.
Export mechanism allows overriding layout, sizing, styling, and Gantt configuration without affecting the live Gantt instance.
Usage
"export-data": ({
url?: string,
format?: "pdf" | "png" | "xlsx" | "mspx",
fileName?: string,
styles?: string,
ganttConfig?: Record<string, any>,
pdf?: {
fitSize?: boolean,
size?: "auto" | "a4" | "a3" | {
width: number,
height: number,
},
landscape?: boolean,
styles?: string,
margins?: {
top?: number,
bottom?:number,
left?: number,
right?: number,
},
header?: string,
footer?: string,
scale?: number,
},
png?: {
fitSize?: boolean,
size?: "auto" | string | {
width: number,
height?: number,
},
landscape?: boolean,
styles?: string,
},
excel?: {
sheetNames?: string[],
visual?: boolean,
dateFormat?: string,
columns?: {
id: string,
header?: string,
type?: "string" | "number" | "date" | "progress",
width?: number,
}[],
},
}) => void;
Parameters
url- (optional) export service endpoint, recommendedhttps://export.svar.dev/gantt/{version}format- (optional)"pdf" | "png" | "xlsx" | "mspx". Default value is "pdf"fileName- (optional) name of the exported file, without extension. Default value is "gantt"styles- (optional) CSS string applied to the exported documentganttConfig- (optional) overrides Gantt configuration for export only
PDF-specific options (pdf)
fitSize- (optional) scale the chart to fit the pagesize- (optional) page size, can be:"auto"- automatic sizing"a4"|"a3"- standard paper sizes{ width: number, height: number }- custom size in pixels
landscape- (optional) boolean, set totruefor landscape orientationstyles- (optional) custom css applied in pdf exportmargins- (optional) page marginstop- (optional) top margin in pixelsbottom- (optional) bottom margin in pixelsleft- (optional) left margin in pixelsright- (optional) right margin in pixels
header- (optional) text or HTML to display in page headerfooter- (optional) text or HTML to display in page footerscale- (optional) manual scaling factor for chart,0.1-2.0
PNG-specific options (png)
fitSize- (optional) scale the chart to fit the pagesize- (optional) page size, can be:"auto"- automatic sizing"a4"/"a3"- standard paper sizes{ width: number, height: number }- custom size in pixels
landscape- (optional) boolean, set totruefor landscape orientationstyles- (optional) custom CSS applied in png export
Excel-specific options (excel)
sheetNames- (optional) an array of sheet names for tasks and links, e.g.,["Tasks", "Links"]visual- (optional) boolean, set totrueto include a visual Gantt chart in excel, defaultfalsecolumns- (optional) columns configuration; each column contains the following properties:- id - (required) data field id
- header - (optional) header text
- type - (optional) "string" | "number" | "date" | "progress"
- width - (optional) column width
dateFormat- (optional) format for date fields, default"yyyy-mm-dd"
MP Project specific options
Data is exported to MS Project without any specific options, but there are 2 ways to do it:
- if you provide the
urlpointing to an export service, data will be exported on the server side - if you do not provide the
url, data will be exported on the client side
api.exec("export-data", {
url, // skip for client-side export
format: "mpsx",
fileName: "gantt",
});
Example
<script>
import { getData } from "../data";
import { Gantt, version } from "@svar/svelte-gantt";
import { Button } from "@svar-ui/svelte-core";
let api;
const data = getData();
const url = "https://export.svar.dev/gantt/" + version;
function handleClick() {
api.exec("export-data", {
url,
format: "pdf",
fileName: "gantt",
pdf: {
size: "a4",
landscape: true,
fitSize: true
}
});
}
</script>
<Button onclick={handleClick}> Export to PDF </Button>
<Gantt
bind:this={api}
tasks={data.tasks}
links={data.links}
scales={data.scales}
/>
Related articles: