数式入門

Aspose.Tasks for .NET API は Microsoft Project (MPP) ファイル内の数式の読み取りと書き込みをサポートします。
数式は既存のプロジェクトデータに基づいて、タスク、リソース、およびプロジェクトのフィールドのカスタム値を計算するために使用されます。

この Formula のプロパティは ExtendedAttributeDefinition クラスは数式の割り当てと読み取りのためのインターフェースを提供します。
もし 無効な数式文字列 が割り当てられた場合、 FormatException 例外がスローされます。

このページでは、数式で使用される文法、サポートされている演算子、関数、および例について紹介します。

数式文法

Microsoft Project は以下の数式文法を使用しており、Aspose.Tasks もこれに従います:

1    Formula -> Formula Binary_Op Primary | Primary
2    Primary -> (Formula) | Unary_Op Primary | Function | ValidFieldName | ValidDoubleValue | "StringLiteral"
3    Function -> ValidFunctionName(Args)
4    Args -> Args Delimiter Formula | Formula | |
5    Delimiter -> , | ;   // Note: Delimiter is culture-specific in XML format ( , or ; ) and persistent in MPP ( , )
6    Binary_Op -> + | - | * | / | & | MOD | ^ | = | <> | < | > | AND | OR
7    Unary_Op -> NOT | + | -

サポートされている要素

1. フィールド

有効な Microsoft Project のフィールド名を使用できます(例: [Duration], [Actual Duration], [Standard Rate])。

2. 演算子

数式は以下をサポートします:

3. 関数

ほとんどの標準的な Microsoft Project 関数がサポートされており、以下を含みます:

例 1: 単純な算術

1var attr = ExtendedAttributeDefinition.CreateTaskDefinition(
2    CustomFieldType.Number,
3    ExtendedAttributeTask.Number1,
4    "WorkPerDay");
5
6attr.Formula = "[Work] / [Duration]";

この数式はタスクの1日あたりの平均作業量を計算します。

例 2: 条件式

1var attr = ExtendedAttributeDefinition.CreateTaskDefinition(
2    CustomFieldType.Text,
3    ExtendedAttributeTask.Text1,
4    "TaskStatus");
5
6attr.Formula = "IIf([% Complete] = 100, \"Done\", \"In Progress\")";

この数式はカスタムフィールドの値を次のように設定します: 「完了」 (タスクが完了している場合)、そうでなければ 「進行中」

エラー処理

関連項目

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.