Проекты импорта и экспорта в формат Primavera
Собственное обменное формат Primavera (XER) от Primavera Systems, Inc. в первую очередь связан с управлением проектами Primavera. Aspose.Tasks для Java предоставляет возможность экспортировать данные проекта Microsoft в форматы Primavera Xer и XML. Эта статья показывает, как экспортировать данные проекта в обе эти форматы.
Импорт данных из файла Primavera
Импорт данных из формата Primavera XML
Aspose.Tasks может импортировать * primavera * xml аналогично форматам Microsoft Project XML и MPP. Класс проекта предоставляет возможность загружать такой тип файла с использованием того же конструктора, что и для других файлов проекта.
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(ImportExportDataToPrimavera.class);
4Project project = new Project(dataDir + "Primavera1.xml");
5// read the project structure
6ProjectFileInfo info = Project.getProjectFileInfo("primavera1.xml");
7System.out.println(info.getProjectFileFormat());
Importing Data from Primavera MPX File 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(ImportExportDataToPrimavera.class);
4Project project = new Project(dataDir +"Primavera1.mpx");
5// read the project structure
6ProjectFileInfo info = Project.getProjectFileInfo("primavera1.mpx");
7System.out.println(info.getProjectFileFormat());
Reading Project UIDs from Primavera XML file
A Primavera XML file may contain multiple projects, each having its own UID. Aspose.Tasks for Java API provides the capability to read all such UIDs from the project and then load a project using a specific id from the list of UIDs.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2PrimaveraXmlReader reader = new PrimaveraXmlReader("primaveraXml.xml");
3List<Integer> listOpProjectUids = reader.getProjectUids();
Reading Primavera XML file with Multiple Projects
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2PrimaveraXmlReadingOptions options = new PrimaveraXmlReadingOptions();
3options.setProjectUid(4557);
4// returns project with special Uid
5Project project = new Project("PrimaveraXmlFile.xml",options);
Importing Project Data from Primavera Database File
1String url = "jdbc:sqlserver://";
2String serverName = "192.168.56.3\\MSSQLSERVER";
3String portNumber = "1433";
4String databaseName = "PrimaveraEDB";
5String userName = "privuser";
6String password = "***";
7PrimaveraDbSettings settings = new PrimaveraDbSettings(url+serverName + ":" + portNumber + ";databaseName=" + databaseName + ";user=" + userName + ";password=" + password, 4502);
8// set driver name
9settings.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
10// note that you have to set the classpath to include the sqljdbc.jar file or the sqljdbc4.jar file, otherwise "Class not found" exception will be thrown
11// here we add classpath dynamically just for testing needs:
12addJDBCDriver(new File("c:\\Program Files (x86)\\Microsoft JDBC Driver 4.0 for SQL Server\\sqljdbc_4.0\\enu\\sqljdbc4.jar"));
13Project project = new Project(settings);
14private static void addJDBCDriver(File file) throws Exception
15{
16 Method method = URLClassLoader.class.getDeclaredMethod("addURL", new Class[]{URL.class});
17 method.setAccessible(true);
18 method.invoke(ClassLoader.getSystemClassLoader(), new Object[]{file.toURI().toURL()});
19}
Support for SQLite Database
1const string connectionString = "Data Source=d:\\DB\\PPMDBSQLite.db";
2const int projectId = 4502;
3PrimaveraDbSettings primaveraDbSettings = new PrimaveraDbSettings(connectionString, projectId);
4primaveraDbSettings.setProviderInvariantName("System.Data.SQLite");
5Project project = new Project(primaveraDbSettings);
Exporting Project Data in Primavera Formats
The SaveFileFormat enumerator is used to specify the project export type as Primavera XML or XER.
Exporting Project Data to Primavera XML 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(ImportExportDataToPrimavera.class);
4Project project = new Project(dataDir + "Project.mpp");
5project.save(dataDir + "saved.xml", SaveFileFormat.PrimaveraP6XML);
Exporting Project Data to Primavera XER 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(ImportExportDataToPrimavera.class);
4Project project = new Project(dataDir + "Project.mpp");
5project.save(dataDir + "saved.xer", SaveFileFormat.PrimaveraXER);
Exporting Project Data to Primavera MPX 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(ImportExportDataToPrimavera.class);
4Project project = new Project(dataDir + "Project.mpp");
5project.save(dataDir + "saved.mpx", SaveFileFormat.MPX);
Primavera XML Save Options
If Primavera XML file doesn’t has any WBS inside (only Activities), Aspose.Tasks can’t read properly this type of file, because the API needs a root task to create a tree of tasks. In this case, the API creates a RootTask, even if it doesn’t exist in the file, to be able to read these particular files. If the user wants to save after reading, it’ll be saving with created RootTask, which did not exist before reading. This option helps to decide how to save into the file - with created RootTask or not. By default, it set to true.
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2Project project = new Project("test.xml");
3PrimaveraXmlSaveOptions options = new PrimaveraXmlSaveOptions();
4options.setSaveRootTask(false);
5project.save("test1.xml",options);