翻譯|使用教程|編輯:董玉霞|2022-06-16 16:34:56.120|閱讀 560 次
概述:DhtmlxGantt 庫允許以 Excel 和 iCal 格式從甘特圖中導(dǎo)出數(shù)據(jù),還可以將數(shù)據(jù)從 Excel 文件導(dǎo)入甘特圖。本文將介紹如何導(dǎo)出到 Excel。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
DhtmlxGantt 庫允許以 Excel 和 iCal 格式從甘特圖中導(dǎo)出數(shù)據(jù),還可以將數(shù)據(jù)從 Excel 文件導(dǎo)入甘特圖。本文將介紹如何導(dǎo)出到 Excel。
有一個通用 API 端點//export.dhtmlx.com/gantt用于所有導(dǎo)出方法(exportToPDF、exportToPNG、exportToMSProject等)和importFromExcel 方法。最大請求大小為 10 MB。
還有一個單獨的 API 端點//export.dhtmlx.com/gantt/project專用于MSProject 導(dǎo)出/導(dǎo)入服務(wù) (僅限 exportToMSProject / importFromMSProject)。最大請求大小:40 MB。
htmlxGantt最新版本 v7.1 開始,要將甘特圖中的數(shù)據(jù)導(dǎo)出到 Excel 文檔,請執(zhí)行以下操作:
<script src="codebase/dhtmlxgantt.js"></script> <script src="http://export.dhtmlx.com/gantt/api.js"></script> <link rel="stylesheet" href="codebase/dhtmlxgantt.css" type="text/css">
<input value="Export to Excel" type="button" onclick='gantt.exportToExcel()'> <script> gantt.init("gantt_here"); gantt.parse(demo_tasks); </script>
exportToExcel ()方法將具有多個屬性的對象作為參數(shù)(所有屬性都是可選的):
使用可選屬性調(diào)用導(dǎo)出方法:
gantt.exportToExcel({ name:"document.xlsx", columns:[ { id:"text", header:"Title", width:150 }, { id:"start_date", header:"Start date", width:250, type:"date" } ], server:"http://myapp.com/myexport/gantt", visual:true, cellColors:true, data:{}, date_format: "dddd d, mmmm yyyy" });
導(dǎo)出模塊期望start_date和end_date列具有Date類型,而duration列具有number類型。
在應(yīng)用自定義模板的情況下,要么返回預(yù)期類型的值,要么在列配置的name屬性中定義不同的值。例如:
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); } }, ... ];
否則,甘特圖數(shù)據(jù)將不會被導(dǎo)出。
設(shè)置要導(dǎo)出的自定義數(shù)據(jù)源
要使用自定義數(shù)據(jù)集(即不使用初始甘特圖中顯示的數(shù)據(jù))導(dǎo)出甘特圖,請使用exportToExcel方法的參數(shù)中的 data屬性:
gantt.exportToExcel({ name:"document.xlsx", data:[ {id:1, text:"Project #1", start_date:"01-04-2020", duration:18}, {id:2, text:"Task #1", start_date:"02-04-2020",duration:8, parent:1}, {id:3, text:"Task #2", start_date:"11-04-2020",duration:8, parent:1} ] });
請注意,您不能將某個 URL 指定為data參數(shù)的值,而只能指定一個數(shù)據(jù)對象。
添加要導(dǎo)出的任務(wù)顏色
可以通過將視覺屬性的值設(shè)置為"base-colors"來將任務(wù)的顏色添加到甘特圖的導(dǎo)出 Excel 文件中:
gantt.exportToExcel({ visual: "base-colors", cellColors: true })
以上就是導(dǎo)出到 Excel的相關(guān)內(nèi)容,更多關(guān)于DhtmlxGantt使用教程的內(nèi)容可進入官網(wǎng)查看。
加入官方社群,第一手掌握DhtmlxGantt 版本動態(tài)以及相關(guān)教程,還能與同行們共同交流,分享學(xué)習(xí)!
DhtmlxGantt技術(shù)交流群:764148812
DhtmlxGantt是針對您的解決方案的交互式JavaScript / HTML5甘特圖。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn