4

I need to read Microsoft Project Plan (.mpp file) from Python application running on Python 2.7.

Not getting ANY resources or pointers on the web for the same.

Any ideas?

Jon Iles
  • 2,519
  • 1
  • 20
  • 30
infoadmin12345
  • 211
  • 1
  • 4
  • 10

3 Answers3

4
  1. You need to install pywin3 (Python for Windows extensions).
  2. You can operate on .mpp files.

Example:

import win32com.client

doc = 'C:\\Project1.mpp'
try:
  mpp = win32com.client.Dispatch("MSProject.Application")
  mpp.Visible = 1
  try:
    mpp.FileOpen(doc)
    proj = mpp.ActiveProject
    print proj.BuiltinDocumentProperties(11), ",", proj.BuiltinDocumentProperties(12)
  except Exception, e:
    print "Error", e
  mpp.FileSave()
  mpp.Quit()
except Exception, e:
  print "Error opening file",e
fsenart
  • 5,661
  • 2
  • 35
  • 54
  • what if the OP doesn't use Windows or have Project installed? – darkphoenix Jul 10 '12 at 17:06
  • Actually, there is no solution if you are using another OS than Windows. Maybe using WINE on Linux or something similar. But I suggest that trying to develop Windows-specific code in a Linux Dev environment (or Mac) is creating a rod for your own back. – fsenart Jul 10 '12 at 19:11
  • What do you mean when you say if the Project is installed? You want to deal with .mpp files isn't it? – fsenart Jul 10 '12 at 19:11
  • 1
    The code supplied is good enough to open the File Browse/Open prompt where one needs to navigate to the mpp file. It just fails from there giving TypeError: 'bool' object is not callable. Any ideas how the file can be opened programmatically and also how to read the data from mpp file? Using dir(mpp object) does not provide too much of useful information. A complete working example would be really appreciated. Thanks for your efforts. – infoadmin12345 Jul 11 '12 at 09:55
  • @infoadmin12345 See [MS Project VBA Dcoumentation](https://learn.microsoft.com/en-us/office/vba/api/project.task) Once you have the file open you can use the VBA documentation to get the rest. Eg "for task in proj.Tasks: print(task.getField(mpp.field_name_to_field_constant('Start')))" – Peter Jan 06 '22 at 15:17
2

You may find that you can achieve what you need using MPXJ although you will either need to be using a JVM-based Python (e.g. Jython) to work with the Java version of the library, or a CLR-based Python (e.g IronPython or Python.Net) to use the .Net version of the library, or you'll need to use a bridge library (e.g. JPype).

Jon Iles
  • 2,519
  • 1
  • 20
  • 30
0

Python package of Aspose.Tasks Cloud manipulate MS Project & Oracle Primavera files without any dependency. It is a paid API but free trial plan provides 150 API calls per month.

P.S: I work as support developer at Aspose.

Tilal Ahmad
  • 940
  • 5
  • 9