Free Support Forum - aspose.com

Unable to set Finish date on a Task

Hi,


I am not able to achieve a simple objective. I am trying to create a simple project with a simple task that starts on 29th December 2016 and ends 4 Jan 2016. Please provide a simple code sample for this.

Hi George,


Thank you for contacting Aspose support team.

You may set the task start date and duration instead of start/finish date. Please give a try to the following sample code which creates a task and sets its start date and duration.

<span style=“font-size: 9pt; font-family: “Courier New”;”>java.util.Calendar
startDate = java.util.Calendar.getInstance();

startDate.set(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>2016<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>11<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>29<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>8<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>0<span style=“font-size: 9pt; font-family: “Courier New”;”>, <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>0<span style=“font-size: 9pt; font-family: “Courier New”;”>);



Project project1 = <span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>new
<span style=“font-size: 9pt; font-family: “Courier New”;”>Project(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“Blank2010.mpp”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

project1.set(Prj.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>START_DATE
<span style=“font-size: 9pt; font-family: “Courier New”;”>, startDate.getTime());



Task task1 = project1.getRootTask().getChildren().add(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>“Task 1”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

task1.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>START
<span style=“font-size: 9pt; font-family: “Courier New”;”>, startDate.getTime());

task1.set(Tsk.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>DURATION
<span style=“font-size: 9pt; font-family: “Courier New”;”>, project1.getDuration(<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:blue”>40<span style=“font-size: 9pt; font-family: “Courier New”;”>, TimeUnitType.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>Hour
<span style=“font-size: 9pt; font-family: “Courier New”;”>));



project1.save(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“project1.mpp”
<span style=“font-size: 9pt; font-family: “Courier New”;”>, SaveFileFormat.<span style=“font-size:9.0pt;
font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;color:#660E7A”>MPP
<span style=“font-size: 9pt; font-family: “Courier New”;”>);<o:p></o:p>

Please feel free to write us back if you have any other query in this regard.