B4J Question Class: Reading MS Project Files with MPXJ

Mashiane

Expert
Licensed User
Longtime User
Hi there

The purpose of this class is to read a MS Project file using MPXJ from http://www.mpxj.org and return the contents, this should include

1. Resources
2. Tasks
3. Predecessors
4. Assignments
5. Project Properties


MashMSProject
  • ParseProjectProperties (m As Map) As MSProjectProperties
    parse the property properties map to a type
  • ParseResource (m As Map) As MSProjectResource
    parse the resource to the given type
  • ParseTask (m As Map) As MSProjectTask
    parse the task to the given type
  • Parse (m As Map) As signment
    parse the assignment to the given type
  • ParsePredecessor (m As Map) As MSProjectPredecessor
    parse the predecessor to the given type
  • Read (dir As String, fil As String)
    read the ms project file and return a map
    with keys resources,assignments, tasks, predecessors etc

So Far

1. Below we see an mpp (microsoft project) file opened with ProjectLibre. There is no need for MS Project to be installed to read them using MPXJ.

2. The code being called in AppStart (a non-ui app in b4j) is all that is needed to return resources and task details from the proejct, a class called ImportMSProject

3. The returned record by the class is a Map that contains a list of all resources and tasks, the start and finish date of the project.

4. This can be customised to return all sorts of project information as per MPXJ (Microsoft Project Exchange) class specifications.

MPXJ.gif


How to use the class

B4X:
'initialize the ms project reader
    Dim imsp As MashMSProject
    imsp.Initialize
    'process the reading of the ms project file
    imsp.Read(File.dirapp,"office.mpp")
    'check if this is initialized
    'read the project propeties
    Dim properties As Map = imsp.Properties
    'read the project properties and parse them to a type
    Dim prop As MSProjectProperties
    prop = imsp.ParseProjectProperties(properties)
    Log(prop.title)
      
        'read the rest of the project stuff
    Dim resources As List = imsp.Resources
    Dim tasks As List = imsp.Tasks
    Dim assignments As List = imsp.Assignments
    Dim predecessors As List = imsp.Predecessors
    For Each resource As Map In resources
        Dim res As MSProjectResource
        res = imsp.ParseResource(resource)
        Log(res.name)
    Next
    For Each task As Map In tasks
        Dim tsk As MSProjectTask
        tsk = imsp.ParseTask(task)
        Log(tsk.name)
        Log(tsk.complete)
    Next
    For Each assignment As Map In assignments
        Dim assign As MSProjectAssignment
        assign = imsp.ParseAssignment(assignment)
        Log(assign.resourceuniqueid)
        Log(assign.taskuniqueid)
    Next
    For Each predecessor As Map In predecessors
        Dim pred As MSProjectPredecessor
        pred = imsp.ParsePredecessor(predecessor)
        Log(pred.lag)
        Log(pred.sourcetask)
        Log(pred.targettask)
    Next


Thank you.
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Looking at the different data segments returned by the class, each a map (and more data can be added easily to be returned depending on need)

Project Properties

B4X:
{
    "cost": 0,
    "comments": "",
    "manager": "",
    "docversion": null,
    "author": "Heather Tank",
    "subject": "",
    "start": "Mon Jun 02 08:00:00 CAT 2014",
    "title": "PE - Working with Reports",
    "revision": 1,
    "duration": 0,
    "name": null,
    "finish": "Tue Oct 28 17:00:00 CAT 2014",
    "company": "",
    "category": null,
    "complete": 0,
    "uniqueid": null
}

Resource

B4X:
{
    "notes": "ACE Carpentry\nAttn: Sue Johnson\n1458 Wood Drive\nMinneapolis, MN 55401",
    "initials": "C",
    "name": "Carpenters",
    "id": 15,
    "uniqueid": 15,
    "email": null
}

Task

B4X:
{
    "notes": "",
    "critical": true,
    "start": "Tue Oct 28 17:00:00 CAT 2014",
    "wbs": "3.2.5",
    "resources": null,
    "priority": 500,
    "parentid": 36,
    "duration": 0,
    "parentuniqueid": 36,
    "milestone": true,
    "responsible": null,
    "name": "Server Room Moving Phase Complete",
    "finish": "Tue Oct 28 17:00:00 CAT 2014",
    "id": 41,
    "complete": 0,
    "deadline": null,
    "uniqueid": 41,
    "durationtype": "d"
}

Assignments (i.e. resource & task links)

B4X:
{
    "taskuniqueid": 26,
    "resourceuniqueid": 15
}

Predecessors

B4X:
{
    "lag": 0,
    "targettask": 2,
    "type": "FF",
    "uniqueid": 1,
    "sourcetask": 3
}
 
Last edited:
Upvote 0
Top