php解析mpp文件中的多级任务

获取层级的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还有好多没用上,还有待于继续研究

转载于:https://www.cnblogs.com/baby123/p/8777021.html

自己写的示例 仅供参考: public static void main(String[] args) { File file; file = new File("e:\\客户管理项目计划V1.0.mpp"); LinkedHashMap infoMap = new LinkedHashMap(); Map userSbMap = new HashMap(); List resourceList = new ArrayList(); String a = readMpp(file, infoMap, userSbMap, resourceList); } public static String readMpp(File file, LinkedHashMap infoMap, Map userSbMap, List resourceList) { MPPFile mpp; String result = ""; try { mpp = new MPPFile(file); LinkedList allList = mpp.getAllTasks(); allList.remove(0); for (int i = 0; i < allList.size(); i++) { Task t = (Task) allList.get(i); Map taskMap = new HashMap(); String flag = t.getUniqueID().toString(); taskMap.put("唯一标识号", t.getUniqueID().toString()); taskMap.put("标识号", t.getID().toString()); taskMap.put("任务名称", t.getName()); taskMap.put("大纲级别", t.getOutlineLevel().toString()); //处理开始时间 Date planStartDate = t.getStart(); String planStart = "-1"; if (planStartDate != null) { planStart = new Long(planStartDate.getTime()).toString(); } //处理完成时间 Date planStopDate = t.getFinish(); String planFinish = "-1"; if (planStopDate != null) { planFinish = new Long(planStopDate.getTime()).toString(); } //处理实际开始时间 Date actStartDate = t.getActualStart(); String actStart = "-1"; if (actStartDate != null) { actStart = new Long(actStartDate.getTime()).toString(); } //处理实际结束日期 Date actStopDate = t.getActualFinish(); String actFinish = "-1"; if (actStopDate != null) { actFinish = new Long(actStopDate.getTime()).toString(); } //处理里程碑 Boolean markedB = t.getMilestone(); String y_or_n = "否"; if (markedB != null) { boolean marked = markedB.booleanValue(); if (marked) { y_or_n = "是"; } } //处理资源 List userList = new ArrayList(); LinkedList resources = t.getResourceAssignments(); if
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值