我正在尝试使用MPXJ - Java从MS Project2010 .mpp文件中提取基本任务和资源信息。打开文件并转储所有任务都没有问题,但在尝试访问分配给任务的资源时出现了问题。我正在调用Task.GetResourceNames(),但它每次都返回null。我也尝试过调用Task.GetResourceAssignments(),但每次都返回null。
我创建了一个非常非常简单的项目,有一个摘要任务,三个子任务,链接在一起,并为每个任务分配了不同的资源。
当我运行我的程序时,我看到了所有的任务,但是对GetResourceNames()的调用仍然返回null。
我是不是通过错误的接口来做这件事?
发布于 2013-01-23 06:32:15
您可以在javadoc中看到,对于mpp文件,GetResourceNames()总是返回null。为了从特定任务中获取资源名称,我是这样做的:
List<ResourceAssignment> Resources = task.getResourceAssignments();
// getResourceAssignments() return a list of ResourceAssignment of a specific task.
Iterator i = Resources.iterator();
while (i.hasNext()) {
ResourceAssignment ra = (ResourceAssignment) i.next();
Resource r = ra.getResource();
// we get the resource from the resource assignment
System.out.println("\t Assigned Resources : " + r.getName());
// print the name of the Resource. If you want to do the same than GetResourceNames, just add each name in a String and you will have the same results at the end.
} 希望这能有所帮助。
https://stackoverflow.com/questions/13408188
复制相似问题