Convertir les données du projet pour Excel en C ++
Cet article montre comment enregistrer les données du projet au format XLSX à l’aide d’Aspose.Tasks pour C ++.
La classe Project expose la méthode de sauvegarde qui est utilisée pour enregistrer un projet dans divers formats. La méthode de sauvegarde vous permet d’enregistrer les tâches de projet, les ressources et les affectations pour séparer les feuilles de calcul au format XLSX à l’aide du type d’énumération SaveFileFormat.
Pour enregistrer un projet sur xlsx:
- Chargez un fichier de projet Microsoft.
- Enregistrez le projet sur XLSX à l’aide de SaveFileFormat.xlsx.
Enregistrer un projet comme xlsx
Les lignes de code suivantes montrent comment y parvenir en utilisant C ++.
1// Read the input Project file
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
3
4// Save the Project as XLSX
5project->Save(dataDir + u"SaveProjectAsXLSX_out.xlsx", Aspose::Tasks::Saving::SaveFileFormat::XLSX);
Using XlsxOptions
With XlsxOptions, you can modify how the project is exported.
1// Read the input Project file
2System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
3
4System::SharedPtr<XlsxOptions> options = System::MakeObject<XlsxOptions>();
5
6// Add desired Gantt Chart columns
7System::SharedPtr<GanttChartColumn> col = System::MakeObject<GanttChartColumn>(u"WBS", 100, &UsingXlsxOptions::_anonymous_method_0);
8options->get_View()->get_Columns()->Add(col);
9
10// Add desired resource view columns
11System::SharedPtr<ResourceViewColumn> rscCol = System::MakeObject<ResourceViewColumn>(u"Cost center", 100, &UsingXlsxOptions::_anonymous_method_1);
12options->get_ResourceView()->get_Columns()->Add(rscCol);
13
14// Add desired assignment view columns
15System::SharedPtr<AssignmentViewColumn> assnCol = System::MakeObject<AssignmentViewColumn>(u"Notes", 200, &UsingXlsxOptions::_anonymous_method_2);
16options->get_AssignmentView()->get_Columns()->Add(assnCol);
17
18project->Save(dataDir + u"UsingXlsxOptions_out.xlsx", options);
Save Project Data to Spreadsheet2003 XML
There are two ways to save data to Spreadsheet2003 XML format: default, or using save options. Using the SaveFileFormat instance, the default view data is saved.
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"CreateProject2.mpp");
2project->Save(dataDir + u"SaveProjectDataToSpreadsheet2003XML_out.xml", Aspose::Tasks::Saving::SaveFileFormat::Spreadsheet2003);
Using Spreadsheet2003SaveOptions
Aspose.Tasks for C++ provides Spreadsheet2003SaveOptions for modifying the view data.
1System::SharedPtr<Spreadsheet2003SaveOptions> options = System::MakeObject<Spreadsheet2003SaveOptions>();
2System::SharedPtr<GanttChartColumn> col = System::MakeObject<GanttChartColumn>(u"WBS", 100, &UsingSpreadsheet2003SaveOptions::_anonymous_method_0);
3options->get_View()->get_Columns()->Add(col);
4
5System::SharedPtr<ResourceViewColumn> rscCol = System::MakeObject<ResourceViewColumn>(u"Cost center", 100, &UsingSpreadsheet2003SaveOptions::_anonymous_method_1);
6options->get_ResourceView()->get_Columns()->Add(rscCol);
7
8System::SharedPtr<AssignmentViewColumn> assnCol = System::MakeObject<AssignmentViewColumn>(u"Notes", 200, &UsingSpreadsheet2003SaveOptions::_anonymous_method_2);
9options->get_AssignmentView()->get_Columns()->Add(assnCol);
10
11project->Save(dataDir + u"UsingSpreadsheet2003SaveOptions_out.xml", options);