Сохранение данных проекта в CSV, текст, форматы MPT

Microsoft Project (MSP) позволяет разработчикам сохранять данные проекта (MPP/XML) в шаблонах запятой (CSV), текста и MPT. Aspose.Tasks также позволяет сохранять данные проекта в тех же форматах, аналогичных MSP. Это достигается с использованием стандартного метода сохранения, выявленного классом Project, как показано с образцами кода ниже.

Преобразование в HTML

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2String dataDir = Utils.getDataDir(SaveAsCsvTextAndTemplate.class);
 3Project project = new Project(dataDir + "sample.mpp");
 4HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
 5
 6//Determines whether to include project name in HTML title (true by default)
 7htmlSaveOptions.setIncludeProjectNameInTitle(true);
 8
 9//Determines whether to include project name in HTML page header  (true by default)
10htmlSaveOptions.setIncludeProjectNameInPageHeader(false);
11
12htmlSaveOptions.setPages(new ArrayList());
13htmlSaveOptions.getPages().add(1);
14project.save("output.html", htmlSaveOptions);

Controlling Document Header Name during Export to HTML

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2String dataDir = Utils.getDataDir(SaveAsCsvTextAndTemplate.class);
 3Project project = new Project(dataDir + "sample.mpp");
 4HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
 5
 6//Determines whether to include project name in HTML title (true by default)
 7htmlSaveOptions.setIncludeProjectNameInTitle(true);
 8
 9//Determines whether to include project name in HTML page header  (true by default)
10htmlSaveOptions.setIncludeProjectNameInPageHeader(false);
11
12
13htmlSaveOptions.setPages(new ArrayList());
14htmlSaveOptions.getPages().add(1);
15project.save("output.html", htmlSaveOptions);

Saving a Project as CSV

The following code snippet shows how to save a project as a CSV format.

1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(SaveAsCsvTextAndTemplate.class);
4Project project = new Project(dataDir + "Project5.mpp");
5project.save(dataDir + "Project5.csv", SaveFileFormat.CSV);

Save Project to Text

1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir(SaveAsCsvTextAndTemplate.class);
4
5Project project = new Project(dataDir + "Project5.mpp");
6project.save(dataDir + "Project5.txt", SaveFileFormat.TXT);

Save Project Data as Template (MPT)

The following code snippet shows how to save a project as an MPT format.

 1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
 2// The path to the documents directory.
 3String dataDir = Utils.getDataDir(SaveAsCsvTextAndTemplate.class);
 4
 5String projectName = "Blank2010.mpp"; // any mpp file (here 2010 format
 6                                        // used)
 7Project project = new Project(projectName);
 8ProjectFileInfo projectFileInfo = Project.getProjectFileInfo(dataDir + "Blank2010.mpp");
 9
10if (FileFormat.MPP14 == projectFileInfo.getProjectFileFormat()) {
11    System.out.println("Project file format is ok");
12}
13SaveTemplateOptions options = new SaveTemplateOptions();
14options.setRemoveActualValues(true);
15options.setRemoveBaselineValues(true);
16
17String templateName = "result.mpt";
18project.saveAsTemplate(templateName);
19
20ProjectFileInfo templateFileInfo = Project.getProjectFileInfo(templateName);
21if (FileFormat.MPT14 == templateFileInfo.getProjectFileFormat()) {
22    System.out.println("Template FileFormat is ok");
23}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.