Конвертировать данные проекта в Excel в C ++
Эта статья демонстрирует, как сохранить данные проекта в формате XLSX с использованием Aspose.Tasks для C ++.
Класс Project раскрывает метод сохранения, который используется для сохранения проекта в различных форматах. Метод сохранения позволяет сохранить задачи, ресурсы и задания проекта для отдельных рабочих листов в формате XLSX, используя тип перечисления SaveFileFormat.
Чтобы сохранить проект в XLSX:
- Загрузите файл проекта Microsoft.
- Сохраните проект в XLSX с помощью saveFileFormat.xlsx.
Сохранение проекта как xlsx
Следующие строки кода демонстрируют, как достичь этого, используя 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);