Question

i am trying to update mpx file using MPXWrite,

Actually i converted mpp file to mpx file so that now i am able to read all the tasks and task details. But i want to update % Completion on particular task in mpx file how i do that.

Can any one provide code for that.

Thanks in Advance.. Please help me out from this problem

// Like this i am reading mpx file

 private static void readMPX(String inputFile){

   File f = new File(inputFile);
   MPXReader read1 = new MPXReader();
   ProjectFile pFile = null;

   try{
        pFile = read1.read(f);
       }catch(Exception e){
           e.printStackTrace();
       }
    List llist=pFile.getAllTasks();

   for(int i=1;i<10/*llist.size()*/;i++)
   {

   Task t=(Task)llist.get(i);
   System.out.println("------------------------------------");
   System.out.println("Task Details : "+i  +llist.get(i));
   System.out.println("WBS : "+t.getWBS());
   System.out.println("WBS Leve : "+t.getWBSLevel());
   System.out.println("Task name : "+t.getName());
   System.out.println("Duration : "+t.getDuration());
   //System.out.println("Task Unique ID : "+t.getUniqueID());
 //  System.out.println("Task Unique ID : "+t.getUniqueID());
   System.out.println("Base Line Start : "+t.getBaselineStart());
   System.out.println("Base Line Finish : "+t.getBaselineFinish());
   System.out.println("Actual Start Date : "+t.getActualStart());
 //  System.out.println("\tFinish Date : "+t.getFinish());
   System.out.println("Actual End Date : "+t.getActualFinish());
   System.out.println("% Complete : "+t.getPercentageComplete());
   //getSubTasks(t,t.getUniqueID());
   System.out.println("------------------------------------");
   }

  }
Was it helpful?

Solution 2

Its a restriction from Microsoft. We cant write back to mpp file.

OTHER TIPS

Here is some sample code for you:

private static void readMPX(String inputFile, String outputFile)
{
   File f = new File(inputFile);
   MPXReader read1 = new MPXReader();
   ProjectFile pFile = read1.read(f);

   // Select the task you want to update
   // Here we are just selecting the first task
   Task task = pFile.getTaskByID(1);

   // Let's set it to 60% complete
   task.setPercentageComplete(60);

   // Now we write the result to a new file
   new MPXWriter().write(pFile, outputFile);   
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top