Microsoft Project Export
There is built in support for exporting the gantt contents into MS Project compatible XML, that can be opened in Project.
This is illustrated in the sample:
<install path>\Samples\GanttControlExportToProjectXML
To export the contents of a gantt into Project XML, you can create a Project document from an empty Project XML in memory and add tasks and resources as shown below:
saveProject = new RadiantQ.ProjectModel.Project(JsonData);
saveProject.initFrom(ganttControl.Model);
for (var i = 0; i < ganttControl.ActivityViews.length; i++) {
......
......
}
saveProject.calculateTasksEndTime();
var xml = js2xmlparser("Project", saveProject.projectElem);
window.JSON.toXML(savedJson, "Project");
The full source can be seen in the sample referenced above.
Microsoft Project Import
MS Project XML format contains a whole lot of features, not all of which are used by / compatible with the gantt. When you try to import a Project XML into the gantt, you can expect to see the following information imported and the rest ignored:
Task Specific Information
APIs allow you to open a stream of Project XML files, create a Project Document in memory and initialize a gantt from this as shown below.
This is also illustrated in the sample <install path>\Samples\GanttControlMSProjectXMLBinding
|
function readBlob() { var fileElement = $('#files'); var file = fileElement[0].files[0]; var reader = new FileReader(); // If we use onloadend, we need to check the readyState. reader.onloadend = function (evt) { if (evt.target.readyState == FileReader.DONE) { // DONE == 2 var txt = evt.target.result; var parser = new DOMParser(); var xml = parser.parseFromString(txt, "text/xml"); init(xml); } }; fileElement.replaceWith(fileElement = fileElement.clone(true)); reader.readAsText(file); } function init(xml) { var json = $.xml2json(xml); project = new RadiantQ.ProjectModel.Project(json); $gantt_container.GanttControl({ "DataSource": null, "ResourceItemsSource": null }); var delayUpdates1 = new RadiantQ.Gantt.Utils.DelayUpdates() { $gantt_container.GanttControl({ WorkTimeSchedule: project.BaseCalendar.Schedule, ResourceItemsSource: project.ResourceList, DataSource: project.Tasks }); } delayUpdates1.Dispose(); var delayUpdates2 = new RadiantQ.Gantt.Utils.DelayUpdates() { gantt = $gantt_container.data("GanttControl"); var $GanttChart = gantt.GetGanttChart(); $GanttChart.GanttChart({ AnchorTime: project.Tasks[0].StartDate.clone() }); } delayUpdates2.Dispose(); } |
Take a look at the above sample for a fully functional example.
© RadiantQ 2022. All Rights Reserved.