翻译|使用教程|编辑:杨鹏连|2020-12-07 10:42:53.007|阅读 953 次
概述:甘特组件允许将链接,任务和资源导出到MS Project中。本文介绍了如何从MS Project导出和导入。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
dhtmlxGantt是用于跨浏览器和跨平台应用程序的功能齐全的Gantt图表。可满足项目管理应用程序的所有需求,是最完善的甘特图图表库。它允许你创建动态甘特图,并以一个方便的图形化方式可视化项目进度。有了dhtmlxGantt,你可以显示活动之间的依赖关系,显示具有完成百分比阴影的当前任务状态以及组织活动到树结构。
导出到MS Project
甘特组件允许将链接,任务和资源导出到MS Project中。
要将数据从甘特图导出到MS Project,请执行以下操作:
<script src="codebase/dhtmlxgantt.js"></script> <script src="//export.dhtmlx.com/gantt/api.js"></script> <link rel="stylesheet" href="codebase/dhtmlxgantt.css" type="text/css">
gantt.exportToMSProject();该方法将向远程服务发送请求,该服务将输出XML Project文件或返回url以下载生成的文件。
响应
响应将包含以下结构的JSON:
{
data: {},
config: {},
resources: [],
worktime: {}
}
所述exportToMSProject()方法作为一个参数的对象与多个属性(所有属性是可选的):
gantt.exportToMSProject({
name:'custom.xml'
});
gantt.exportToMSProject({
auto_scheduling: false
});
gantt.exportToMSProject({
skip_circular_links: false
});
gantt.exportToMSProject({
project: {
'Author': 'I am!',
'MinutesPerDay': function () {
return gantt.config.hours_per_day * 60;
}
}
});
该对象的属性对应于Project实体的适当属性。可以在此处找到受支持属性的列表。这些属性可以包含固定值或在调用export时将执行的函数。
gantt.exportToMSProject({
tasks: {
'StartVariance': function (task) {
if (task.startVariance)
return task.startVariance;
else
return 0;
},
'PercentWorkComplete': function (task) {
return (task.progress + 0.1);
},
'Custom': function (task) {
return 'Custom value';
},
'Custom 2': 'My Custom value'
}
});
该对象的属性与Task实体的适当属性相对应,这里是受支持属性的列表。这些属性可以包含固定值或函数,在调用export时将为数据集中的每个任务调用这些函数。
gantt.exportToMSProject({
callback: function(res){
alert(res.url);
}
});
gantt.exportToMSProject({
resources: [
{"id":"1","name":"John","type":"work"},
{"id":"2","name":"Mike","type":"work"},
{"id":"3","name":"Anna","type":"work"}
]
});
可能的资源类型为“工作”,“成本”,“材料”。使用任务配置的ResourceAssignments属性指定资源分配:var users = [// resources
{key:'0', label: "N/A"},
{key:'1', label: "John"},
{key:'2', label: "Mike"},
{key:'3', label: "Anna"}
];
gantt.exportToMSProject({
resources: users
.filter(function(u){
if(u.key === '0')//skip the default option
return false;
return true;
})
.map(function(u){
return {
id: u.key,
name: u.label,
type: "work"
};
}),
tasks: {
ResourceAssignments: function(task){
return task.user;
}
}
});
所述ResourceAssignments属性被设定为开出任务对象作为参数并返回一个字符串/数值或串/数值的数组的函数:tasks: {
ResourceAssignments: function(task){
return [task.user, task.office];
}
}
gantt.exportToMSProject({
server:"//myapp.com/myexport/gantt"
});
从MS Project导入
为了转换XML或MPP MS Project文件,您需要将以下请求发送到导出服务:
<form action="//export.dhtmlx.com/gantt" method="POST"
enctype="multipart/form-data">
<input type="file" name="file" />
<input type="hidden" name="type" value="msproject-parse">
<button type="submit">Get</button>
</form>
另外,您可以使用客户端API,如下所示:gantt.importFromMSProject({
data: file,
taskProperties: ["Notes", "Name"],
callback: function (project) {
if (project) {
gantt.clearAll();
if (project.config.duration_unit) {
gantt.config.duration_unit = project.config.duration_unit;
}
gantt.parse(project.data);
}
}
});
其中file是File的实例,其中应包含XML或MPP Project文件。响应
响应将包含以下结构的JSON:
{
data: {},
config: {},
resources: [],
worktime: {}
}
设置持续时间单位
要设置预期的持续时间单位,还可以将durationUnit(“分钟”,“小时”,“天”,“周”,“月”,“年”)字符串发送到服务器。
<form action="//export.dhtmlx.com/gantt" method="POST"
enctype="multipart/form-data">
<input type="file" name="file" />
<input type="hidden" name="type" value="msproject-parse">
<input type="hidden" name="data"
value="{ \"durationUnit\": \"hour\" }" />
<button type="submit">Get</button>
</form>
要么gantt.importFromMSProject({
data: file,
durationUnit: "hour",
callback: function(project){}
});
获取项目的属性
要获取项目字段,可以将带有一系列必需字段的projectProperties输入发送到服务器。它将Project实体的任意属性提取 到输出的config属性中。这是受支持的属性的列表。
<form action="//export.dhtmlx.com/gantt" method="POST"
enctype="multipart/form-data">
<input type="file" name="file" />
<input type="hidden" name="type" value="msproject-parse">
<input type="hidden" name="data"
value="{ \"projectProperties\": [\"Author\", \"Title\"] }" />
<button type="submit">Get</button>
</form>
要么gantt.importFromMSProject({
data: file,
durationUnit: "hour",
projectProperties: ["Author", "Title"],
callback: function(project){
var config = project.config;
alert(config.$custom_properties.Author);
}
});
获取任务属性
要获取任务字段,可以将带有一系列必需字段的taskProperties输入发送到服务器。它提取Task实体的任意属性。这是受支持的属性的列表:
<form action="//export.dhtmlx.com/gantt" method="POST"
enctype="multipart/form-data">
<input type="file" name="file" />
<input type="hidden" name="type" value="msproject-parse">
<input type="hidden" name="data"
value="{ \"taskProperties\": [\"Contact\", \"Priority\"] }" />
<button type="submit">Get</button>
</form>
要么gantt.importFromMSProject({
data: file,
durationUnit: "hour",
taskProperties: ["Contact", "Priority"],
callback: function(project){
var config = project.config;
alert(config.$custom_properties.Author);
gantt.parse(project.data);
}
});
gantt.attachEvent("onTaskLoading", function(task) {
if (task.$custom_data) {
task.contact = task.$custom_data["Contact"];
task.priority = task.$custom_data["priority"];
delete task.$custom_data;
}
return true;
});
对请求大小和大文件导入的限制
MSProject导出/导入服务有两个API端点:
gantt.importFromMSProject({
server:"//export.dhtmlx.com/gantt",
data: file,
callback: function(project){
// some logic
}
});
如果未指定端点,则默认使用//export.dhtmlx.com/gantt。以下调用等效于上述调用:gantt.importFromMSProject({
data: file,
callback: function(project){
// some logic
}
});
为了导出或导入超过4MB限制的大型项目,可以使用第二个端点:gantt.importFromMSProject({
server:"//export.dhtmlx.com/gantt/project",
data: file,
callback: function(project){
// some logic
}
});
它允许发送最大40MB的请求,并支持MS Project导出和导入。它只能用于MS Project导出。
任何其他方法,例如gantt.exportToPDF({server:“ //export.dhtmlx.com/gantt/project”})都应返回服务器错误。
关产品推荐:
VARCHART XGantt:支持ActiveX、.Net等平台的C#甘特图控件
AnyGantt:构建复杂且内容丰富的甘特图的理想工具
jQuery Gantt Package:基于HTML5 / jQuery的跨平台jQuery Gantt包
phGantt Time Package:对任务和时间的分配管理的甘特图
APS帮助提升企业生产效率,真正实现生产计划可视化呈现与控制,快速有效响应不同场景的生产计划,提高准时交货能力,提高产能和资源利用率
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
文章转载自: