问题描述
爱美网www.aimei999.com人员推荐!MPXJ是一个开源的包,网址http://mpxj.sourceforge.net/index.html它需要POI的支持。它可以读取MPP文件(不能写MPP文件!!!要经过XML过渡。。。)可以读写MPX文件,MPX就是一个纯文本文件,里面有TASK,Resource之类的信息,按一定格式书写的。Project98及之前版本可以另存为MPX文件,从Project2000开始就不支持另存为MPX格式了,但是,它们仍然可以读取MPX文件。MPXJ的读写的类主要有这么几个:读:net.sf.mpxj.mpp.MPPReader:readsMicrosoftProjectMPPfilesnet.sf.mpxj.mpx.MPXReader:readsMicrosoftMPXfilesnet.sf.mpxj.mspdi.MSPDIReader:readsMicrosoftMSPDI(XML)filesnet.sf.mpxj.mpd.MPDIReader:readsMicrosoftMPDfilesnet.sf.mpxj.planner.PlannerReader:readsPlanner(XML)files写:net.sf.mpxj.mpx.MPXWriter:writesMicrosoftMPXfilesnet.sf.mpxj.mspdi.MSPDIWriter:writesMicrosoftMSPDI(XML)filesnet.sf.mpxj.planner.PlannerWriter:writesPlanner(XML)files所以,目前可以做的就是:1.读取MPP文件信息,写入DB之类的……2.new一个ProjectFile,写入Task,Resources,Calendar之类的信息,然后使用MPXWriter写入MPX文件,然后用Project打开,好像会有个导入数据的对话框。……MPXJ的数据结构:一个Project由Task,Resources,Calendar构成,Task与Calendar,Resources与Calendar都有关系。Task和Resources通过ResourceAssignment关联。===========================================================下面是使用MPXWrite的一段代码,转载的,参考参考。packagempx;importjava.util.Locale;importnet.sf.mpxj.DateRange;importnet.sf.mpxj.Day;importnet.sf.mpxj.Duration;importnet.sf.mpxj.FieldType;importnet.sf.mpxj.ProjectCalendar;importnet.sf.mpxj.ProjectCalendarHours;importnet.sf.mpxj.ProjectFile;importnet.sf.mpxj.ProjectHeader;importnet.sf.mpxj.Relation;importnet.sf.mpxj.RelationType;importnet.sf.mpxj.Resource;importnet.sf.mpxj.Task;importnet.sf.mpxj.TaskField;importnet.sf.mpxj.TimeUnit;importnet.sf.mpxj.mpx.MPXWriter;importnet.sf.mpxj.utility.NumberUtility;publicclassCreateMPX{publicCreateMPX(){}publicstaticvoidmain(Stringargs[]){try{create("d:\output.MPX");}catch(Exceptionex){ex.printStackTrace(System.out);}}privatestaticvoidcreate(Stringfilename)throwsException{ProjectFilefile=newProjectFile();Tasktask1=file.addTask();task1.setName("task1");task1.setUniqueID(1);task1.setID(1);task1.setOutlineLevel(task0.getOutlineLevel()+1);Tasktask11=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");Tasktask12=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);//前置关系Relationr=task12.addPredecessor(task11);r.setType(RelationType.FINISH_START);r.setTaskUniqueID(task11.getUniqueID());ProjectCalendarpc=file.addBaseCalendar();//设置工作日历这里设的周1-7全部工作,呵呵如不设默认为5天工作制pc.setName("压榨民工");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);ProjectCalendarHoursh1=pc.addCalendarHours(Day.SUNDAY);h1.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START1,ProjectCalendar.DEFAULT_END1));h1.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START2,ProjectCalendar.DEFAULT_END2));ProjectCalendarHoursh2=pc.addCalendarHours(Day.MONDAY);h2.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START1,ProjectCalendar.DEFAULT_END1));h2.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START2,ProjectCalendar.DEFAULT_END2));ProjectCalendarHoursh3=pc.addCalendarHours(Day.TUESDAY);h3.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START1,ProjectCalendar.DEFAULT_END1));h3.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START2,ProjectCalendar.DEFAULT_END2));ProjectCalendarHoursh4=pc.addCalendarHours(Day.WEDNESDAY);h4.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START1,ProjectCalendar.DEFAULT_END1));h4.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START2,ProjectCalendar.DEFAULT_END2));ProjectCalendarHoursh5=pc.addCalendarHours(Day.THURSDAY);h5.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START1,ProjectCalendar.DEFAULT_END1));h5.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START2,ProjectCalendar.DEFAULT_END2));ProjectCalendarHoursh6=pc.addCalendarHours(Day.FRIDAY);h6.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START1,ProjectCalendar.DEFAULT_END1));h6.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START2,ProjectCalendar.DEFAULT_END2));ProjectCalendarHoursh7=pc.addCalendarHours(Day.SATURDAY);h7.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START1,ProjectCalendar.DEFAULT_END1));h7.addDateRange(newDateRange(ProjectCalendar.DEFAULT_START2,ProjectCalendar.DEFAULT_END2));ProjectHeaderph=file.getProjectHeader();ph.setCalendarName(pc.getName());MPXWriterwriter=newMPXWriter();//设置中文writer.setLocale(Locale.CHINESE);writer.write(file,filename);}}
解决方案
解决方案二:
该回复于2011-07-27 09:15:46被版主删除