Home > Mobile >  How to make MPXJ-Library show work column in mpp File using Java
How to make MPXJ-Library show work column in mpp File using Java

Time:12-01

I'm doing an internal Project, in Java, where i have to read an Excel and Parse it into a mpp respectively a MS Project compatible .xml file. I'm creating the file and everythings working fine. But i want to show the columns "Work" and "ID" by default.

I can show them in MS Projects and the values are as I expect them to be, but i have to select and show them. Is there a possibility to show them by default when you open the .xml file?

I tried a lot and searched:

as well as StackOverflow. But i didn't found any Information helping me out or it wasn't helpful cause methods changed and i didn't found the equivalent new ones.

this is where i fill the tasks and resources of my mpp.

if (!extractedRow.getElement().isEmpty())
            {
                element = contract.addTask();
                element.setName(extractedRow.getElement());
                element.setStart(startingDate);
                element.setOutlineLevel(LookUp.Mpp_Conversion_Element_OutlineLevel());
                element.setID(id  );

            }
            else if (!extractedRow.getWorkpackage().isEmpty())
            {
                workpackage = Objects.requireNonNull(element).addTask();
                workpackage.setName(extractedRow.getWorkpackage());
                workpackage.setOutlineLevel(LookUp.Mpp_Conversion_Workpackage_OutlineLevel());
                workpackage.setID(id  );

            }
            else if (!extractedRow.getTask().isEmpty())
            {
                task = Objects.requireNonNull(workpackage).addTask();
                task.setName(extractedRow.getTask());
                task.setType(TaskType.FIXED_WORK);
                task.setOutlineLevel(LookUp.Mpp_Conversion_Task_OutlineLevel());
                task.setWork(Duration.getInstance(extractedRow.getEstimatedTime(), TimeUnit.HOURS));
                task.setDuration(Duration.getInstance(extractedRow.getEstimatedTime() / 8, TimeUnit.DAYS));
                task.setRemainingWork(Duration.getInstance(extractedRow.getEstimatedTime(), TimeUnit.HOURS));
                task.setID(id  );

                if (!extractedRow.getRole().isEmpty())
                {
                    for (Resource resource : _project.getResources())
                    {
                        if (resource.getName().equals(_filereader.get_mapper().getMapping(extractedRow.getRole())))
                        {
                            assn = Objects.requireNonNull(task).addResourceAssignment(resource);
                            assn.setStart(task.getStart());
                            assn.setWork(Duration.getInstance(extractedRow.getEstimatedTime(), TimeUnit.HOURS));
                        }
                    }
                }
            }

Kind Regards

CodePudding user response:

Unfortunately using an MPP file is the only way for you to specify the visual appearance of a schedule automatically when it is opened by Microsoft Project.

You have a few options:

  • I believe Aspose.Tasks can generate MPP files, so it may be that as part of that you can configure the layout you want
  • As you are already working with Excel you may want to consider using VBA which would allow you to both extract the data you need from Excel, populate the schedule in MS Project and configure the layout of the schedule.
  • Finally, if you want to use MPXJ, when you generate the MSPDI file and import it into Microsoft Project you are given some options about how the file is opened (as a new schedule, append to an existing schedule, update an existing schedule). If you create an empty "template" MPP file with the visual layout you require, using the append or update options when you open the XML file and selecting the template file as the target should give you a finished file using the data you've generated with the visual layout you need.
  • Related