Java를위한 aspose
Contents
[
Hide
Show
]ASPOSE.TASK의 Java API는 MPP 프로젝트 파일에 대한 읽기/쓰기 공식을 지원합니다. ExtendedAttributedEfinition의 공식 속성은 공식 값을 읽기위한 인터페이스를 제공합니다. 이 기사에서는 MPP 파일의 엔터프라이즈 확장 속성뿐만 아니라 로컬에서 공식을 읽는 방법에 대해 설명합니다.
MPP 파일 형식에 대한 확장 된 속성의 공식 작성
1// The path to the documents directory.
2String dataDir = Utils.getDataDir(WriteReadFormula.class);
3
4Project project = new Project(dataDir + "New project 2010.mpp");
5project.set(Prj.NEW_TASKS_ARE_MANUAL, new NullableBool(false));
6
7// create new custom field (Task Text1) with formula which will double task cost
8ExtendedAttributeDefinition attr = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Text,
9 ExtendedAttributeTask.Text1, "Custom");
10attr.setAlias("Double Costs");
11attr.setFormula("[Cost]*2");
12
13project.getExtendedAttributes().add(attr);
14
15// add a task to see the result in MSP
16Task task = project.getRootTask().getChildren().add("Task");
17// set task cost
18task.set(Tsk.COST, BigDecimal.valueOf(100));
19// see the result in the attached screenshot (result.jpg)
20project.save(dataDir + "saved.mpp", SaveFileFormat.MPP);
Reading Formulas in Local and Enterprise Extended Attributes from MPP file
1// The path to the documents directory.
2String dataDir = Utils.getDataDir(WriteReadFormula.class);
3
4Project proj = new Project(dataDir + "FormulaField.mpp"); // attached test mpp
5ExtendedAttributeDefinition attr = proj.getExtendedAttributes().get(0);
6
7System.out.println("Attribute Formula: " + attr.getFormula());
Read-Only Access to Custom Field Values when Using Formulas
1// The path to the documents directory.
2String dataDir = Utils.getDataDir(WriteReadFormula.class);
3
4Project project = new Project();
5
6ExtendedAttributeDefinition attribute = ExtendedAttributeDefinition.createTaskDefinition(CustomFieldType.Cost,
7 ExtendedAttributeTask.Cost1, "");
8attribute.setFormula("[Cost]-[Actual Cost]");
9
10project.getExtendedAttributes().add(attribute);
11
12// Add task
13Task task = project.getRootTask().getChildren().add("Task");
14
15// Create extended attribute
16ExtendedAttribute extendedAttribute = attribute.createExtendedAttribute();
17task.getExtendedAttributes().add(extendedAttribute);
18
19// Display if extended attributes are read only or not
20System.out.println(
21 extendedAttribute.getValueReadOnly() == true ? "Value is Read only" : "Value is not read only");
22extendedAttribute.setTextValue("-36755");
23System.out.println(
24 extendedAttribute.getTextValue() == " " ? "Formula values are read-only" : "Values are not read-only");