• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

to write to a mpx file.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i need to read from a mpx file, append a new task or insert a new task and write it back to the mpx file. I am able to read from the mpx file and write it as such. But i am not able to append or insert a new task and write it back to the mpx file. Can someone help me with the code to the above mentioned task.

Hari
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is an mpx file?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is an MPX file? Are you talking about a Microsoft Project export file? (found this on http://www.wotsit.org).

Found this with Google: MPXJ - Microsoft Project Exchange in Java
 
hari babu gopinathan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MPX file is Microsoft Project Exchange and MPXJ is the class used to handle this file in java.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you are already using MPXJ? Why didn't you say so?

What does it mean when you say "i am not able to append or insert a new task and write it back to the mpx file"? Does it mean you don't know how to do that, or did you already try something, but it didn't work as you expected? Did you get a compile-time or runtime error? Did you read the documentation for MPXJ?

It will be much easier to get your question answered if you explain in detail what the problem is, what you tried already and where exactly you got stuck.
 
hari babu gopinathan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i was able to append a task to an mpx file but the task was not visible in the MS Project 2003 while opening, i,e Through program if i read the newly added task, i can able to read the new Task. But i was successful with microsoft xml format that is MSPDI.the code which was used is,




import java.io.PrintStream;
import java.text.SimpleDateFormat;
import net.sf.mpxj.*;
import net.sf.mpxj.mpp.MPPReader;
import net.sf.mpxj.mpx.MPXReader;
import net.sf.mpxj.mpx.MPXWriter;
import net.sf.mpxj.mspdi.*;
import net.sf.mpxj.mspdi.MSPDIWriter;
import net.sf.mpxj.utility.NumberUtility;
import net.sf.mpxj.writer.ProjectWriter;

public class CreateXML
{

public CreateXML ()
{
}

public static void main(String args[])
{
try
{
create("d:\\output.XML");
}
catch(Exception ex)
{
ex.printStackTrace(System.out);
}
}

private static ProjectWriter getWriter(String filename)
{
String suffix;
if(filename.length() < 4)
suffix = ".MPX";
else
suffix = filename.substring(filename.length() - 4).toUpperCase();
ProjectWriter result;
if(suffix.equals(".XML"))
result = new MSPDIWriter();
else
result = new MPXWriter();
return result;
}

private static void create(String filename)
throws Exception
{
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
MSPDIReader r=new MSPDIReader();
ProjectFile file=r.read("d:\\input.XML");

file.setAutoTaskID(true);
file.setAutoTaskUniqueID(true);
file.setAutoResourceID(true);
file.setAutoResourceUniqueID(true);
file.setAutoOutlineLevel(true);
file.setAutoOutlineNumber(true);
file.setAutoWBS(true);
file.setAutoCalendarUniqueID(true);

ProjectCalendar calendar = file.addDefaultBaseCalendar();
ProjectCalendarException exception = calendar.addCalendarException();
exception.setFromDate(df.parse("13/06/2007"));
exception.setToDate(df.parse("13/06/2007"));
exception.setWorking(false);
ProjectHeader header = file.getProjectHeader();
header.setStartDate(df.parse("1/06/2007"));
Resource resource1 = file.addResource();
resource1.setName("Resource1");
Resource resource2 = file.addResource();
resource2.setName("Resource2");
resource2.setMaxUnits(new Double(50D));



Task task1 = file.addTask();
task1.setName("Main Task2");
task1.setStart(df.parse("12/07/2007"));
task1.setDuration(Duration.getInstance(100D, TimeUnit.DAYS));

Task task2 = task1.addTask();
task2.setName("T13");
task2.setDuration(Duration.getInstance(5, TimeUnit.DAYS));
task2.setStart(df.parse("6/10/2007"));
task2.setPercentageComplete(NumberUtility.getDouble(50D));

ProjectWriter writer = getWriter(filename);
writer.write(file, filename);
}
}



But with the above code, The new task is not appending in the proper Order..
 
hari babu gopinathan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
can someone help me with the above mentioned code. I need to append the task to a micrososft xml file i.e MSPDI file, but when i do with the above mentioned code, the first appended task gets inserted after the first task in the file. Also when i try to add some different set of tasks, the first set of added tasks gets added again i,e inserted.
[ June 19, 2007: Message edited by: hari babu gopinathan ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe a call to ProjectFile.updateStructure would help. Just a wild guess, though.
 
hari babu gopinathan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
updateStructure() doesn't solve the problem.
 
hari babu gopinathan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
at last i was successful in appending a task to mspdi file .This time i had used xml DOM concept, and it was easy.
 
Honk if you love justice! And honk twice for tiny ads!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic