Formules d'écriture et de lecture avec Aspose.Tasks pour Java
Contents
[
Hide
Show
]Aspose.Tasks pour l’API Java prend en charge les formules de lecture / écriture aux fichiers du projet MPP. La propriété de formule de l’extensionAttributeDefinition fournit l’interface pour lire la valeur de formule. Cet article décrit comment lire les formules des attributs étendus locaux et d’entreprise du fichier MPP.
Écriture de formules dans des attributs étendus aux formats de fichiers 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");