获取层级的project任务 参考
启动javabridge
java -jar JavaBridge.jar SERVLET_LOCAL:8089
1.读取mpp文件
$file_path = "/new.mpp"; $file_path = getcwd() . $file_path; if (!file_exists($file_path)) { var_dump("文件不存在"); return; } $mppRead = new Java('net.sf.mpxj.mpp.MPPReader'); try { $Filecontent = $mppRead->read($file_path); } catch (Exception $e) { var_dump($e); return; }
2.获取任务
获取project的任务
$allTasks = $Filecontent->getChildTasks(); $tasks_size = java_values($allTasks->size()); if($tasks_size){ getChildren($allTasks[0]); }
说明:
$Filecontent->getChildTasks()获取的是文件,即$allTasks[0]为project文件,再向下是任务
获取任务的基本信息
function getChildren($task) { $child = $task->getChildTasks(); $tasks_size = java_values($child->size()); $data = array(); $formatter = new Java('java.text.SimpleDateFormat', "yyyy-MM-dd HH:mm:ss"); for ($i = 0; $i < $tasks_size; $i++) { $tmp = getResource($child[$i]); $items = array(); $items['id'] = $child[$i]->getID() . ''; $items['level'] = $child[$i]->getOutlineLevel() . ''; $items['uniqueID'] = $child[$i]->getUniqueID() . ''; $items['name'] = $child[$i]->getName() . ''; $items['duration'] = $child[$i]->getDuration() . ''; $start = $child[$i]->getStart(); $items['start'] = $formatter->format($start) . ''; $finish = $child[$i]->getFinish(); $items['finish'] = $formatter->format($finish) . ''; $items['percentComplete'] = $child[$i]->getPercentageComplete() . ''; //成本金额 $items['cost'] = $child[$i]->getCost() . ''; //实际成本ACWP $items['ActualCost'] = $child[$i]->getActualCost() . ''; //联系人字段包含负责任务的个人的姓名 $items['contact'] = $child[$i]->getContact() . ''; //设置执行工作的实际成本 $items['ACWP'] = $child[$i]->getACWP() . ''; $items['BCWS'] = $child[$i]->getBCWS() . ''; $items['BCWP'] = $child[$i]->getBCWP() . ''; //任务的总工时或人员小时数 $items['work'] = $child[$i]->getWork() . ''; //获取剩余工作字段值 $items['RemainingWork'] = $child[$i]->getRemainingWork() . ''; //自定义文本 $items['Text'] = $child[$i]->getText(1) . ''; $items['Text1'] = $child[$i]->getText(2) . ''; $items['Text2'] = $child[$i]->getText(3) . ''; $children = getChildren($child[$i]); if ($children) { $items['children'] = $children; } $data[] = $items; } return $data; }
获取资源 详见
获取前置任务 详见
踩了不少坑,终于解析出来了想要的信息
MPXJ还有好多没用上,还有待于继续研究
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/20383.html