我通过MPXJ库在MS Project中导出项目,我有一个问题:
如何将周六(或周日)的具体日期设置为工作日而不是周末? (在ProjectCalendar或其他地方)
例如,2014年10月18日(星期六)设定为工作日,但另一个星期六需要是周末。
public ProjectCalendar initCalendar(ProjectFile projectfile, int calendarId, Date startDate, Date endDate) {
ProjectCalendar defaultCalendar = projectfile.addDefaultBaseCalendar();
/*Setup standart working week*/
defaultCalendar.setName("Standart");
defaultCalendar.setWorkingDay(Day.MONDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.THURSDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.WEDNESDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.TUESDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.FRIDAY, DayType.WORKING);
defaultCalendar.setWorkingDay(Day.SATURDAY, DayType.NON_WORKING);
defaultCalendar.setWorkingDay(Day.SUNDAY, DayType.NON_WORKING);
ProjectCalendarHours pch;
pch = defaultCalendar.addCalendarHours(Day.MONDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
pch = defaultCalendar.addCalendarHours(Day.THURSDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
pch = defaultCalendar.addCalendarHours(Day.WEDNESDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
pch = defaultCalendar.addCalendarHours(Day.TUESDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
pch = defaultCalendar.addCalendarHours(Day.FRIDAY);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
/* setup holydays*/
List<Date> workingHollidays = DBHelper.getWorkingHolidays(ppmCalendarId, startDate, endDate);
for (Date work : workingHollidays) {
ProjectCalendarException ex = defaultCalendar.addCalendarException(work, work);
}
/*There is I need change stendart week and setup 6-days working week (Saturday is work day) */
/*something like that*/
Date workindDay = new SimpleDateFormat("dd.MM.yyyy").parse("18.10.2014");
defaultCalendar.setWorkingDay(workindDay, DayType.NON_WORKING); // This code not work
pch = defaultCalendar.addCalendarHours(workindDay); // This code not work
pch.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
pch.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
}
并且在ountput中,Microsoft Project xml将是这样的标记:
<Calendar>
...
<WeekDay>
<DayType>
0
</DayType>
<DayWorking>
1
</DayWorking>
<TimePeriod>
<FromDate>2014-10-18T00:00:00</FromDate>
<ToDate>2014-10-18T23:59:00</ToDate>
</TimePeriod>
<WorkingTimes>
<WorkingTime>
<FromTime>09:00:00</FromTime>
<ToTime>13:00:00</ToTime>
</WorkingTime>
<WorkingTime>
<FromTime>14:00:00</FromTime>
<ToTime>18:00:00</ToTime>
</WorkingTime>
</WorkingTimes>
</WeekDay>
...
</Calendar>
感谢。
答案 0 :(得分:1)
我找到了答案 有自定义日期作为工作日期的代码:
Date workindDay = new SimpleDateFormat("dd.MM.yyyy").parse("18.10.2014");
ProjectCalendarException ex = defaultCalendar.addCalendarException(workindDay, workindDay);
ex.addRange(ProjectCalendar.DEFAULT_WORKING_MORNING);
ex.addRange(ProjectCalendar.DEFAULT_WORKING_AFTERNOON);
范围顺序很重要。