开发者

MPXJ consistently adds blank task name...is MPXJ better than Interop?

I'm trying to use MPXJ to create project file from a hierarchy that exists in my code. The following hierarchy needs to be converted:

  • Division
    • Customer
      • Contract
        • Projects
          • Project details (start/end dates, etc.)

My code for creating the .mpx is as follows:

private void BuildExport()
    {

        net.sf.mpxj.ProjectFile file = new net.sf.mpxj.ProjectFile开发者_C百科();
        net.sf.mpxj.ProjectCalendar cal = file.addDefaultBaseCalendar();

        //Microsoft.Office.Interop.MSProject.Application projApp = new Microsoft.Office.Interop.MSProject.Application();
        //projApp.Visible = true;
        //projApp.FileNew();

        string firstDate = string.Empty;

        foreach (IZCpTreeViewItem div in Divisions)
        {
            net.sf.mpxj.Task divTask = file.addTask();
            divTask.setName(div.Name);

            //Microsoft.Office.Interop.MSProject.Task newTask = projApp.ActiveProject.Tasks.Add(div.Name);

            //newTask.OutlineLevel = 1;

            foreach (IZCpTreeViewItem cust in div.Subitems)
            {
                net.sf.mpxj.Task custTask = null;

                if (cust.Subitems.Count > 0)
                {
                    custTask = divTask.addTask();
                    custTask.setName(cust.Name);
                }                    

                //Microsoft.Office.Interop.MSProject.Task custTask = newTask.OutlineChildren.Add(cust.Name);

                //custTask.OutlineLevel = 2;

                foreach (IZCpTreeViewItem contractVm in cust.Subitems)
                {
                    net.sf.mpxj.Task contTask = custTask.addTask();
                    contTask.setName(contractVm.Name);

                    //Microsoft.Office.Interop.MSProject.Task contractTask = custTask.OutlineChildren.Add(contractVm.Name);

                    //contractTask.OutlineLevel = 3;

                    foreach (ZCpProjectViewModel proj in (contractVm as ZCpContractViewModel).Projects)
                    {
                        net.sf.mpxj.Task projTask = contTask.addTask();
                        projTask.setName(proj.Name);

                        //Microsoft.Office.Interop.MSProject.Task projTask = contractTask.OutlineChildren.Add(proj.Project.Name);

                        //projTask.OutlineLevel = 4;

                        foreach (ZCpProjectDetailViewModel detail in proj.ProjectDetail)
                        {
                            net.sf.mpxj.Task projDTask = projTask.addTask();
                            projDTask.setName(detail.ProjectDetail.CostClass);
                            projDTask.setStart(detail.StartDate.HasValue ? new java.util.Date(detail.StartDate.ToString()) : null);

                            //Microsoft.Office.Interop.MSProject.Task projDetailTask = projTask.OutlineChildren.Add(detail.ProjectDetail.CostClass);

                            //projDetailTask.Start = String.Format("{0}", detail.StartDate.ToString());
                            //projDetailTask.Finish = String.Format("{0}", detail.EndDate.ToString());

                            //projDetailTask.OutlineLevel = 5;
                        }
                    }
                }
            }
        }

        net.sf.mpxj.writer.ProjectWriter writer = new MPXWriter();
        writer.write(file, "example.mpx");
    }

The commented out code is the interop code I was using before I found MPXJ. My problem is that after I run this block, my .mpx file has some customers that are blank (even though I put breakpoints in when adding these customers and ensured the names were not empty). Is there something else I need to set to ensure all names are use?

Should I just go back to using the incredibly slow (17 minutes to create ~6000 tasks) interop code. Is there a way to write to the Projcet file using interop without having the Project file open.

Thanks!!


Having spoken to Ryan offline, and looked at his data - here is what we found.

Ryan can generate both MPX and MSPDI files using MPXJ, with a minimal set of attributes for each task. In the example code shown above, just a name and start date are being supplied. All of the task names appear as expected in both the MPX and MSPDI files.

When opened in Project 2003 or Project 2007, all of the task names are visible... however if you start working through the file and collapsing the task hierarchy (in the case of the data Ryan has generated, collapsing all of the tasks beneath the customer level) occasionally one of the tasks will just be blanked out. All of the data for that task will simply disappear, and no amount of expanding and collapsing the task hierarchy will bring it back.

The behaviour seems to be worse in Project 2010, where many of the task names are blank as soon as the project loads.

It looks like this is a weird MS Project issue related to importing files that don't have certain attributes present. In this case Ryan added a finish date to his export, and that seemed to do the trick. When opened in Project 2010, the files which include the finish date attribute correctly display all of the task names. When opened in Project 2003, I couldn't reporduce the random "blanking" problem which I saw with the original file.

On a more general note, there is an example class which ships with MPXJ called MpxjCreate which gives an example of the minimum set of attributes required to ensure that tasks, resources, and resource assignments display as expected when files created with MPXJ are opened in MS Project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜