Primavera 형식으로 프로젝트를 수입 및 수출합니다
Primavera Systems, Inc.의 Primavera의 독점 교환 형식 (XER)은 주로 Primavera 프로젝트 관리와 관련이 있습니다. Java 용 Tasks는 Microsoft 프로젝트 데이터를 Primavera XER 및 XML 형식으로 내보낼 수있는 기능을 제공합니다. 이 기사는 프로젝트 데이터를 두 형식으로 내보내는 방법을 보여줍니다.
Primavera 파일에서 데이터 가져 오기
Primavera XML 형식에서 데이터 가져 오기
Aspose.Tasks는 Microsoft Project XML 및 MPP 형식과 유사한 * Primavera * XML을 가져올 수 있습니다. 프로젝트 클래스는 다른 프로젝트 파일에 사용 된 것과 동일한 생성자를 사용하여 이러한 유형의 파일을로드 할 수있는 기능을 제공합니다.
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);