MPP 파일에서 VBA 정보를 읽습니다
ASPOSE.TASK 용 C ++ API는 MPP 파일에서 VBA 정보를 읽는 것을 지원합니다. 여기에는 다음과 같은 작업이 포함됩니다.
- VBA 정보.
- 프로젝트에 포함 된 모듈 정보.
- 참조 프로젝트에 저장된 정보.
vbaproject 클래스는 프로젝트 파일에서 VBA 정보를 읽는 주요 클래스입니다. 또한 VBA 프로젝트 파일의 자세한 내용을 읽기위한 모듈 및 참조 컬렉션이 있습니다. 이 기사는 코드 샘플의 도움으로 이러한 모든의 사용을 보여줍니다.
VBA 프로젝트 정보 읽기
다음 코드 예제는 vbaproject 및 프로젝트 클래스의 도움으로 VBA 프로젝트 정보를 읽는 방법을 보여줍니다.
1// Loading project file
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
3
4System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
5
6System::Console::WriteLine(System::String(u"VbaProject.Name ") + vbaProject->get_Name());
7System::Console::WriteLine(System::String(u"VbaProject.Description ") + vbaProject->get_Description());
8System::Console::WriteLine(System::String(u"VbaProject.CompilationArguments") + vbaProject->get_CompilationArguments());
9System::Console::WriteLine(System::String(u"VbaProject.HelpContextId") + vbaProject->get_HelpContextId());
Reading References Information from VBA
The following code example demonstrates how to read VBA References Information from VBA with the help of VbaProject, Project and VbaReference class
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
2
3System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
4System::SharedPtr<VbaReferenceCollection> references = vbaProject->get_References();
5System::Console::WriteLine(u"Reference count ", System::ObjectExt::Box<int32_t>(references->get_Count()));
6
7System::SharedPtr<VbaReference> reference = vbaProject->get_References()->ToList()->idx_get(0);
8System::Console::WriteLine(System::String(u"Identifier: ") + reference->get_LibIdentifier());
9System::Console::WriteLine(System::String(u"Name: ") + reference->get_Name());
10
11reference = vbaProject->get_References()->ToList()->idx_get(1);
12System::Console::WriteLine(System::String(u"Identifier: ") + reference->get_LibIdentifier());
13System::Console::WriteLine(System::String(u"Name: ") + reference->get_Name());
14
15reference = vbaProject->get_References()->ToList()->idx_get(2);
16System::Console::WriteLine(System::String(u"Identifier: ") + reference->get_LibIdentifier());
17System::Console::WriteLine(System::String(u"Name: ") + reference->get_Name());
Reading Modules Information from VBA
The following code example demonstrates how to read modules information from VBA with the help of VbaProject, Project and IVbaModule class
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
2
3System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
4System::Console::WriteLine(System::String(u"Total Modules Count: ") + vbaProject->get_Modules()->get_Count());
5
6System::SharedPtr<IVbaModule> vbaModule = vbaProject->get_Modules()->ToList()->idx_get(0);
7System::Console::WriteLine(System::String(u"Module Name: ") + vbaModule->get_Name());
8System::Console::WriteLine(System::String(u"Source Code: ") + vbaModule->get_SourceCode());
Reading Module Attributes Information from VBA
The following code example demonstrates how to read modules attributes from VBA with the help of VbaProject, Project and IVbaModule class
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"VbaProject1.mpp");
2System::SharedPtr<VbaProject> vbaProject = project->get_VbaProject();
3System::SharedPtr<IVbaModule> vbaModule = vbaProject->get_Modules()->ToList()->idx_get(0);
4
5System::Console::WriteLine(System::String(u"Attributes Count: ") + vbaModule->get_Attributes()->get_Count());
6System::Console::WriteLine(System::String(u"VB_Name: ") + vbaModule->get_Attributes()->ToList()->idx_get(0)->get_Key());
7System::Console::WriteLine(System::String(u"Module1: ") + vbaModule->get_Attributes()->ToList()->idx_get(0)->get_Value());