このトピックでは、C++を使用してMicrosoft Project fileメタデータを抽出する方法を説明します。 MS Projectに依存せずに、単純なAPI呼び出しを使用してC++でMPPファイルとそのメタデータ情報にアクセスする方法を確認します。
C++を使用してMicrosoftProjectファイルのメタデータを抽出する手順
- NuGetパッケージマネージャーツールからAspose.Tasks for C++をインストールします
- Aspose::Tasks名前空間への参照を追加します
- Projectクラスインスタンスをインスタンス化してMPPファイルをロードし、メタデータ情報を抽出します
- Prjクラスの静的メソッドを使用してさまざまなプロパティのメタデータ情報を抽出します
数行のコードで単純なAPI呼び出しを使用することにより、C++でMPPファイルのメタデータを抽出できます。 MPPファイルにアクセスし、C++のPrjクラスによって公開されている目的のメタデータプロパティを反復処理する必要があります。
C++を使用してMicrosoftProjectファイルのメタデータを抽出するコード
#pragma once | |
#include <Project.h> | |
#include <Task.h> | |
#include<License/License.h> | |
#include<Saving/Html/HtmlSaveOptions.h> | |
#include<Prj.h> | |
#include <system/string.h> | |
#include <system/console.h> | |
#include <system/environment.h> | |
#include <system/shared_ptr.h> | |
#include <system/environment.h> | |
#include <system/object_ext.h> | |
#include <system/object.h> | |
#include <stdio.h> | |
using namespace Aspose::Tasks; | |
using namespace Aspose::Tasks::Saving; | |
using namespace System; | |
void ExtractMetaInformation() | |
{ | |
// Setting the license extracting metadata from MPP Project file | |
SharedPtr<License> AsposeTasksLicense = System::MakeObject<License>(); | |
AsposeTasksLicense->SetLicense(u"licFile"); | |
// Source MPP file path and name | |
System::String SourceFile = u"SourceMicrosoftProjectFile.mpp"; | |
// Load the MPP file to extract meta information | |
SharedPtr<Project> MSProjectFile = MakeObject<Project>(SourceFile); | |
// Access and sae different meta information properties inside project file | |
System::String ProjectAuthor = MSProjectFile->Get(Prj::Author()); | |
System::String ProjectCategory = MSProjectFile->Get(Prj::Category()); | |
System::String ProjectCompany = MSProjectFile->Get(Prj::Company()); | |
System::String ProjectComments = MSProjectFile->Get(Prj::Comments()); | |
// Show the meta-data information extracted from the Microsoft Project file | |
System::Console::Write(u"Author:{0}, Catgory:{1}, Company:{2}, Comments:{3}", | |
ProjectAuthor, ProjectCategory, ProjectCompany, ProjectComments); | |
} |
以前、C#でMicrosoftProjectファイルのメタデータを抽出する方法を学びました。ただし、このトピックでは、*MicrosoftProjectメタデータエクストラクタをC++*で実装しました。