Save Project Data to CSV, Text, MPT Formats
Contents
[
Hide
Show
]Microsoft Project (MSP) allows developers to save project data (MPP/XML) to comma delimited (CSV), text and MPT templates. Aspose.Tasks also lets you save project data to the same formats similar to MSP. This is achieved using the standard Save method exposed by the Project class as shown with code samples below.
Converting 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
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}