PHP parsing mpp file

Source: Internet
Author: User
Tags php language

PHP did not find the appropriate package

Java's MPXJ can be implemented

So with Javabridge.jar

1. Install JDK, set environment variables (my version jdk1.8.0_131)

2. Download MPJX

On http://www.mpxj.org/official website Mpxj in Java, go to download page

(My version mpxj-7.0.2)

Unzip, put Mpxj.jar and Lib below the Commons-collections4-4.1.jar, Poi-3.17.jar, Rtfparserkit-1.10.0.jar into the Java installation directory under Jre/lib/ext

Test

New Mpxjtest.java in Www/mpp

 Importnet.sf.mpxj.mpp.*; Importnet.sf.mpxj.MPXJException;ImportNet.sf.mpxj.Resource; Importnet.sf.mpxj.ResourceAssignment;ImportNet.sf.mpxj.Task; ImportNet.sf.mpxj.ProjectFile;Importjava.util.List; ImportJava.io.*;  Public classMpxjtest { Public Static voidMain (string[] args)throwsmpxjexception {File file=NewFile ("Aa.mpp"); Mppreader Mppread=NewMppreader (); ProjectFile PF=mppread.read (file);     System.out.println (PF); List Tasks=pf.getalltasks (); Mpxjtest MT=Newmpxjtest (); System.out.println ("Total Task number:" +tasks.size ()); System.out.println ("Id| Task Name | resource | start Time | end Time | percent Complete");  for(inti = 1; I < tasks.size (); i++) {System.out.println ((Task) tasks.get (i)). Getuniqueid ()+ "|" + (Task) tasks.get (i)). GetName () + "|" + Mt.getresource (Task) Tasks.get (i) + "|" + (Task) tasks.get (i)). Getstart () + "|" + (Task) tasks.get (i)). Getfinish () + "|" +( Task) tasks.get (i)). Getpercentagecomplete ()); }         }  PublicString getresource (Task Task) {StringBuffer BUF=NewStringBuffer (); List Assignments=task.getresourceassignments ();  for(inti = 0; I < assignments.size (); i++) {resourceassignment Assignment=(resourceassignment) assignments. get (i); Resource Resource=Assignment.getresource (); if(Resource! =NULL) {buf.append (Resource.getname ()). Append (" "); }     }    returnbuf.tostring ();} }

3.php calling Java

javabridge.jar--Core Java application package for building Web server interfaces

java.inc--method Packages for PHP language calls, mainly Java classes

Run Javabridge.jar first to start the Web server interface and run the command in the directory where Javabridge.jar is located

Java-jar Javabridge.jar servlet_local:8089

Note:

Without servlet_local:8089, the default is 8080.

Modify the allow_url_include in php.ini to On

Test

New aa.php

<? php require_once ("Http://localhost:8080/JavaBridge/java/Java.inc"= Java ("Java.lang.System" ) ); Echo $System->getproperties ();

Success

Note:

To invoke a class that you have developed, the class must be of the public type. The method to invoke must also be of the public type

4.php Analytic MPP

<?Php$filename= "Aa.mpp"; $data=PARSEMSPJ ($fileName); Echo"Success"; $fp= fopen ('./a.txt ', ' a+b ')); fwrite ($fp, Var_export ($data,true) ; fclose ($fp); function PARSEMSPJ ($fileName) {$file _path=$fileName; Require_once' Http://localhost:8089/JavaBridge/java/Java.inc '; $data= Array ();if(Empty ($file _path)) {return$data;} $mppRead=NewJava (' Net.sf.mpxj.mpp.MPPReader '); $Filecontent= $mppReadRead ($file _path); $Alltasks= $Filecontentgetalltasks (); $Tasks _size= Java_values ($Alltaskssize ()); //id| Task Name | start Time | end Time | percent Complete | resource | Duration     for($i = 1; $i < $Tasks _size; $i + +) {$separator= ' | '; $tmp=getresource ($Alltasks [$i]); $string= $Alltasks [$i]->getuniqueid (). $separator. $Alltasks [$i]->getname (). $separator. $tmp. $separator. $Alltasks [$i]->getstart (). $separator. $Alltasks [$i]->getfinish (). $separator. $Alltasks [$i]->Getpercentagecomplete (); $data []= Explode (' | '), $string); }    return$data;} function GetResource ($task) {$resource= $taskgetresourceassignments (); $size= Java_values ($resourcesize ()); $buf= ' '; if($size >0){     for($i = 0; $i < $size; $i + +) {$tmp= $resource [$i]->getresource (); if(!(Java_is_null ($tmp))) {$buf []= $tmpGetName (); }    }    }    return$buf;}

Will parse out the contents of the file, write A.txt

Parsing the MPP file by PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.