从 4.2 版本开始,dhtmlxScheduler 支持将所有调度器数据导出为 Excel 和 iCal 格式。
有一个共享的 API 端点 https://export.dhtmlx.com/scheduler,用于多种导出方法(如 exportToPDF、exportToPNG 等)。最大请求大小为 10 MB。
要将调度器数据导出为 Excel 文件,请按照以下步骤操作:
<script src="codebase/dhtmlxscheduler.js"></script>
<script src="https://export.dhtmlx.com/scheduler/api.js"></script> <link rel="stylesheet" href="codebase/dhtmlxscheduler.css" type="text/css">
<input value="Export to Excel" type="button" onclick="scheduler.exportToExcel()">
<script> scheduler.init("scheduler_here",new Date(2019,5,30),"month");
scheduler.load("data/events");
</script>
exportToExcel() 方法可以接受一个可选对象,包含以下属性:
name | (string) 输出文件名,需带有 '.xlsx' 扩展名 |
columns | (array) 配置导出表格中的列
|
server | (string) 指定导出请求的 API 端点。可以指向本地安装的导出服务。默认值为 https://export.dhtmlx.com/scheduler |
start | (string|object) 设置要导出的数据起始日期 |
end | (string|object) 设置要导出的数据结束日期 |
调用导出方法并传入可选属性
scheduler.exportToExcel({
name:"My document.xls",
columns:[
{ id:"text", header:"Title", width:150 },
{ id:"start_date", header:"Start date", width:250 }
],
server:"https://myapp.com/myexport/scheduler",
start: new Date(1999, 01, 01),
end: new Date(2022, 01, 01)
});
如需控制导出的 Excel 文件中日期的显示方式,可以这样设置 xml_format 模板:
scheduler.templates.xml_format = scheduler.date.date_to_str("%Y-%m-%d %H:%i");
Related sample: Setting date format
关于日期格式的更多细节,请参阅此处的说明。
要将调度器数据导出为 iCal 字符串,请按照以下步骤操作:
<script src="codebase/dhtmlxscheduler.js"></script>
<script src="https://export.dhtmlx.com/scheduler/api.js"></script> <link rel="stylesheet" href="codebase/dhtmlxscheduler.css" type="text/css">
<input value="Export to iCal" type="button" onclick="scheduler.exportToICal()">
<script> scheduler.init("scheduler_here",new Date(2019,5,30),"month");
scheduler.load("data/events");
</script>
exportToICal() 方法可以接受一个可选对象,包含如下属性:
server | (string) 指定导出请求的 API 端点。可以设置为本地部署的导出服务。默认值为 https://export.dhtmlx.com/scheduler |
调用导出方法并传入可选属性
scheduler.exportToICal({
server:"https://myapp.com/myexport/scheduler"
});
返回顶部