当前位置: 首页 > news >正文

项目管理工具dhtmlxGantt甘特图入门教程(十四):导出/导入 Excel到 iCal

这篇文章给大家讲解利用dhtmlxgantt导入/导出Excel到iCal的操作方法。 

dhtmlxGantt是用于跨浏览器和跨平台应用程序的功能齐全的Gantt图表,可满足应用程序的所有需求,是完善的甘特图图表库

DhtmlxGantt正版试用下载(qun;765665608)icon-default.png?t=N176https://www.evget.com/product/4213/download

dhtmlxGantt库可以让您以Excel和iCal格式从甘特图中导出数据。您还可以将数据从 Excel文件导入甘特图。

1、导出到 Excel

要将甘特图中的数据导出到Excel文档,请执行以下操作:

  • 在页面中包含“https://export.dhtmlx.com/gantt/api.js”文件以启用在线导出服务:
<script src="codebase/dhtmlxgantt.js"></script>
<script src="https://export.dhtmlx.com/gantt/api.js"></script>  
<link rel="stylesheet" href="codebase/dhtmlxgantt.css" type="text/css">
  • 调用exportToExcel方法从甘特图中导出数据:
<input value="Export to Excel" type="button" οnclick='gantt.exportToExcel()'><script>gantt.init("gantt_here");gantt.parse(demo_tasks);
</script>

使用可选属性调用导出方法

gantt.exportToExcel({name:"document.xlsx", columns:[{ id:"text",  header:"Title", width:150 },{ id:"start_date",  header:"Start date", width:250, type:"date" }],server:"https://myapp.com/myexport/gantt",visual:true,cellColors:true,data:{},date_format: "dddd d, mmmm yyyy"
});

默认日期参数

导出模块期望start_date和end_date列具有Date类型,而duration列具有number类型。

在应用自定义模板的情况下,要么返回预期类型的值,要么在列配置的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); }},...
];

否则,甘特图数据将不会被导出。

设置要导出的自定义数据源

要使用自定义数据集(即不使用初始甘特图中显示的数据)导出甘特图,请使用exportToExcel方法的参数中的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}]      
});

添加要导出的任务颜色

您可以通过将视觉属性的值设置为"base-colors"来将任务的颜色添加到甘特图的导出Excel文件中:

gantt.exportToExcel({visual: "base-colors", cellColors: true
})

2、从Excel导入

由于无法自动将Excel文档的任意列映射到甘特数据模型,因此导出服务将文档转换为以JSON形式返回的行数组。将生成的文档转换为甘特图数据是最终开发人员的责任。

为了转换Excel文件,您需要向导出服务发送以下请求:

  • 请求网址 - https://export.dhtmlx.com/gantt
  • 请求方法 - POST
  • 内容类型 -多部分/表单数据

请求参数为:

  • 文件-Excel文件
  • 类型-“excel解析”
  • 数据-(可选)带有设置的JSON字符串

例如:

<form action="https://export.dhtmlx.com/gantt" method="POST" enctype="multipart/form-data"><input type="file" name="file" /><input type="hidden" name="type" value="excel-parse"><button type="submit">Get</button>
</form>

或者,您可以使用客户端 API:

gantt.importFromExcel({server:"https://export.dhtmlx.com/gantt",data: file,callback: function(project){console.log(project)}
});

其中file是File的一个实例,它应该包含一个 Excel (xlsx) 文件。

响应:将包含一个带有对象数组的JSON:

[{ "Name": "Task Name", "Start": "2018-08-11 10:00", "Duration": 8 },...
]

位置:

  • 第一行的值用作导入对象的属性名称。
  • 每行都被序列化为一个单独的对象。
  • 日期值以“%Y-%m-%d %H:%i”格式序列化。

导入设置

导入服务期望导入工作表的第一行是包含列名的标题行。

默认情况下,该服务返回文档的第一页。要返回不同的工作表,请使用工作表参数(从零开始)

gantt.importFromExcel({server:"https://export.dhtmlx.com/gantt",data: file,sheet:2, // print third sheetcallback: function (rows) {}
});

3、导出到iCal

要将数据从甘特图导出到iCal字符串,请执行以下操作:

在页面中包含“https://export.dhtmlx.com/gantt/api.js”文件以启用在线导出服务:

<script src="codebase/dhtmlxgantt.js"></script>
<script src="https://export.dhtmlx.com/gantt/api.js"></script>  
<link rel="stylesheet" href="codebase/dhtmlxgantt.css" type="text/css">

调用exportToICal方法从甘特图中导出数据:

<input value="Export to iCal" type="button" οnclick='gantt.exportToICal()'><script>gantt.init("gantt_here");gantt.parse(demo_tasks);
</script>

导出方法的参数

exportToICal ()方法将具有以下属性的对象作为参数(可选):

  • server - ( string ) 设置请求的 API 端点。可与导出服务的本地安装一起使用。默认值为https://export.dhtmlx.com/gantt;
  • name - ( string ) 允许为文件指定自定义名称和扩展名,但文件仍将以 iCal 格式导出。
gantt.exportToICal({server:"https://myapp.com/myexport/gantt"
});
http://www.lryc.cn/news/22839.html

相关文章:

  • k-means聚类总结
  • char * 和const char *的区别
  • 【剑指offer】JZ3 数组中重复的数字、 JZ4 二维数组中的查找
  • 数据采集 - 笔记
  • 8年测开经验面试28K公司后,吐血整理出高频面试题和答案
  • spring读取properties顺序,重复key问题
  • 什么是api接口?(基本介绍)
  • 【2023全网最全教程】从0到1开发自动化测试框架(建议收藏)
  • 3-5天炒股短线战法指标思想结合----超级短线源码无未来
  • 原始GAN-pytorch-生成MNIST数据集(代码)
  • 注意,这些地区已发布2023年上半年软考报名时间
  • Html引入外部css <link>标签 @import
  • React源码分析8-状态更新的优先级机制
  • 如何在ChatGPT的API中支持多轮对话
  • 华为OD机试模拟题 用 C++ 实现 - 猜字谜(2023.Q1)
  • Containerd容器运行时将会替换Docker?
  • java虚拟机中对象创建过程
  • 3485. 最大异或和
  • SpringBoot:SpringBoot配置文件.properties、.yml 和 .ymal(2)
  • QT 学习之QPA
  • Pytorch中FLOPs和Params计算
  • DP1621国产LCD驱动芯片兼容替代HT1621B
  • Linux 用户管理
  • 前端vue面试题(持续更新中)
  • Java查漏补缺-从入门到精通汇总
  • 软件测试2年半的我,谈谈自己的理解...
  • 什么是SAS硬盘
  • 一文理解服务端渲染SSR的原理,附实战基于vite和webpack打造React和Vue的SSR开发环境
  • Matlab 实用小函数汇总
  • Echarts 仪表盘倾斜一定角度显示,非中间对称