none
write project file RRS feed

Answers

  • Hi,

    You need to download a library named: MPXJ, which could help your Java application to enable to read and edit some files after conversion, see:

    http://mpxj.sourceforge.net/

    And here is sample to which you can refer:

    package mpx;   
      
    import java.util.Locale;   
      
    import net.sf.mpxj.DateRange;   
    import net.sf.mpxj.Day;   
    import net.sf.mpxj.Duration;   
    import net.sf.mpxj.FieldType;   
    import net.sf.mpxj.ProjectCalendar;   
    import net.sf.mpxj.ProjectCalendarHours;   
    import net.sf.mpxj.ProjectFile;   
    import net.sf.mpxj.ProjectHeader;   
    import net.sf.mpxj.Relation;   
    import net.sf.mpxj.RelationType;   
    import net.sf.mpxj.Resource;   
    import net.sf.mpxj.Task;   
    import net.sf.mpxj.TaskField;   
    import net.sf.mpxj.TimeUnit;   
    import net.sf.mpxj.mpx.MPXWriter;   
    import net.sf.mpxj.utility.NumberUtility;   
      
    public class CreateMPX   
    {   
        public CreateMPX()   
        {   
        }   
      
        public static void main(String args[])   
        {   
            try  
            {   
                create("d:\\output.MPX");   
            }   
            catch (Exception ex)   
            {   
                ex.printStackTrace(System.out);   
            }   
        }   
      
           
        private static void create(String filename) throws Exception   
        {   
            ProjectFile file =new ProjectFile();   
                           
            Task task1 = file.addTask();   
            task1.setName("task1");   
            task1.setUniqueID(1);   
            task1.setID(1);   
            task1.setOutlineLevel(task0.getOutlineLevel()+1);   
               
            Task task11 = task1.addTask();   
            task11.setName("task1-1");   
            task11.setDuration(Duration.getInstance(6, TimeUnit.DAYS));   
            task11.setStart(java.sql.Date.valueOf("2008-8-21"));   
            task11.setFinish(java.sql.Date.valueOf("2008-8-26"));   
            task11.setPercentageComplete(NumberUtility.getDouble(90D));   
            task11.setUniqueID(2);   
            task11.setID(2);   
            task11.setResourceNames("one");   
                       
            Task task12 = task1.addTask();   
            task12.setName("task12");   
            task12.setDuration(Duration.getInstance(5, TimeUnit.DAYS));   
            task12.setStart(java.sql.Date.valueOf("2008-8-27"));   
            task12.setFinish(java.sql.Date.valueOf("2008-8-31"));   
            task12.setResourceNames("two");   
            task12.setUniqueID(3);   
            task12.setID(3);   
                   
                        
            Relation r=task12.addPredecessor(task11);      
      
                 r.setType(RelationType.FINISH_START);   
                 r.setTaskUniqueID(task11.getUniqueID());   
               
            ProjectCalendar pc=file.addBaseCalendar();   
               
                      
            pc.setName("Name");   
            pc.setWorkingDay(Day.SUNDAY, true);   
            pc.setWorkingDay(Day.MONDAY, true);   
            pc.setWorkingDay(Day.TUESDAY, true);   
            pc.setWorkingDay(Day.WEDNESDAY, true);   
            pc.setWorkingDay(Day.THURSDAY, true);   
            pc.setWorkingDay(Day.FRIDAY, true);   
            pc.setWorkingDay(Day.SATURDAY, true);   
               
            ProjectCalendarHours h1=pc.addCalendarHours(Day.SUNDAY);   
            h1.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START1, ProjectCalendar.DEFAULT_END1));   
            h1.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START2, ProjectCalendar.DEFAULT_END2));   
               
            ProjectCalendarHours h2=pc.addCalendarHours(Day.MONDAY);   
            h2.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START1, ProjectCalendar.DEFAULT_END1));   
            h2.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START2, ProjectCalendar.DEFAULT_END2));   
               
            ProjectCalendarHours h3=pc.addCalendarHours(Day.TUESDAY);   
            h3.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START1, ProjectCalendar.DEFAULT_END1));   
            h3.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START2, ProjectCalendar.DEFAULT_END2));   
               
            ProjectCalendarHours h4=pc.addCalendarHours(Day.WEDNESDAY);   
            h4.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START1, ProjectCalendar.DEFAULT_END1));   
            h4.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START2, ProjectCalendar.DEFAULT_END2));   
               
            ProjectCalendarHours h5=pc.addCalendarHours(Day.THURSDAY);   
            h5.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START1, ProjectCalendar.DEFAULT_END1));   
            h5.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START2, ProjectCalendar.DEFAULT_END2));   
               
            ProjectCalendarHours h6=pc.addCalendarHours(Day.FRIDAY);   
            h6.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START1, ProjectCalendar.DEFAULT_END1));   
            h6.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START2, ProjectCalendar.DEFAULT_END2));   
               
            ProjectCalendarHours h7=pc.addCalendarHours(Day.SATURDAY);   
            h7.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START1, ProjectCalendar.DEFAULT_END1));   
            h7.addDateRange(new DateRange (ProjectCalendar.DEFAULT_START2, ProjectCalendar.DEFAULT_END2));   
               
               
            ProjectHeader ph=file.getProjectHeader();   
            ph.setCalendarName(pc.getName());   
                       
            MPXWriter writer = new MPXWriter();   
                    
            writer.setLocale(Locale.CHINESE);   
            writer.write(file, filename);   
        }   
    }  

    I hope these information could get you a hint.

    Good day,


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    Sunday, February 19, 2012 5:47 PM
    Moderator