Add holiday to Calendar

Hi,


I want to add some holiday to Calendar, how can I accomplish it?

For example, July 4 2016 is holiday, I want to add it to Calendar and make Project can apply the Calendar.


Best Regards!
Zhencheng.Guo

Hi Zhencheng,


Thank you for contacting Aspose support team.

Please use following sample code to add holiday in the calendar and share the feedback with us.

<span style=“font-size: 9pt; font-family: “Courier New”;”>Project project = <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”>“plain.mpp”
<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:gray”>//Remove an exception

<span style=“font-size: 9pt; font-family: “Courier New”;”>Calendar cal =
project.getCalendars().toList().get(<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:navy”>if
<span style=“font-size: 9pt; font-family: “Courier New”;”>(cal.getExceptions().getCount()

<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:blue”>1<span style=“font-size: 9pt; font-family: “Courier New”;”>)

{

CalendarException exc =
cal.getExceptions().toList().get(<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”;”>);

cal.getExceptions().remove(exc);

}



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Add an exception

<span style=“font-size: 9pt; font-family: “Courier New”;”>CalendarException calExc = <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”;”>CalendarException();



java.util.Calendar calObject = java.util.Calendar.getInstance();

calObject.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”>6<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”>4<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”;”>, <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”;”>);

calExc.setFromDate(calObject.getTime());



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Another exception

<span style=“font-size: 9pt; font-family: “Courier New”;”>calObject.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”>6<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”>4<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”>23<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”>59<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”>59<span style=“font-size: 9pt; font-family: “Courier New”;”>);

calExc.setToDate(calObject.getTime());



calExc.setOccurrences(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:blue”>1<span style=“font-size: 9pt; font-family: “Courier New”;”>);

calExc.setName(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“Holiday”
<span style=“font-size: 9pt; font-family: “Courier New”;”>);

<span style=“font-size: 9pt; font-family: “Courier New”;”>

cal.getExceptions().add(calExc);



<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:
“Times New Roman”;color:gray”>//Display exceptions

<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:navy”>for
<span style=“font-size: 9pt; font-family: “Courier New”;”>(CalendarException calExc1:cal.getExceptions())

{

System.<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:#660E7A”>out
<span style=“font-size: 9pt; font-family: “Courier New”;”>.println(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>"From: "
<span style=“font-size: 9pt; font-family: “Courier New”;”>+ calExc1.getFromDate().toString());

System.<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:#660E7A”>out
<span style=“font-size: 9pt; font-family: “Courier New”;”>.println(<span style=“font-size:9.0pt;font-family:“Courier New”;mso-fareast-font-family:“Times New Roman”;
color:green”>"To: "
<span style=“font-size: 9pt; font-family: “Courier New”;”>+
calExc1.getToDate().toString());

}

project.save(<span style=“font-size:9.0pt;font-family:“Courier New”;
mso-fareast-font-family:“Times New Roman”;color:green”>“Exceptions.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”;”>);