Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HoriLiu/18b85c21cb6884e6b5169cad0f7f70a9 to your computer and use it in GitHub Desktop.
Save HoriLiu/18b85c21cb6884e6b5169cad0f7f70a9 to your computer and use it in GitHub Desktop.
Python wrapper for the MPXJ from MS project 2003 .mpp to excel .xlsx file
import jpype
import mpxj
import pandas as pd
#Ref FAQ for log4j2 in https://www.mpxj.org/faq/
jpype.startJVM("-Dlog4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory")
#Ref https://pypi.org/project/mpxj/
from net.sf.mpxj.reader import UniversalProjectReader
project = UniversalProjectReader().read('example.mpp')
# Extract relevant data
data = []
print("Tasks")
for task in project.getTasks():
if(task.getName()):
print(task.getID().toString() + "\t" + task.getName())
data.append([task.getID().toString(), task.getName(), task.getDuration(), task.getStart(), task.getFinish()])
else:
print(task.getID().toString() + "\t" + "Null")
data.append([task.getID().toString()])
df = pd.DataFrame(data, columns=['ID', 'TaskName', 'WorkDuration', 'StartDate', 'EndDate'])
# Save the data to Excel
df.to_excel('WbsEst.xlsx', index=False)
jpype.shutdownJVM()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment