Write Updated Resource Data in Aspose.Tasks
Introduction
In this tutorial, we’ll guide you through updating Microsoft Project resource data using Aspose.Tasks for Java. Aspose.Tasks is a powerful Java API that allows you to manipulate Microsoft Project files without requiring Microsoft Project to be installed on your system.
Prerequisites
Before we begin, make sure you have the following:
- Java Development Kit (JDK) installed on your system.
- Aspose.Tasks for Java library. You can download it from here.
- Basic knowledge of Java programming.
Import Packages
First, you need to import the necessary packages to work with Aspose.Tasks in your Java code. Add the following import statements to your Java file:
import com.aspose.tasks.Project;
import com.aspose.tasks.Resource;
import com.aspose.tasks.Rsc;
import com.aspose.tasks.SaveFileFormat;
Step 1: Set Up Your Data Directory
Define the directory where your data files are located:
String dataDir = "Your Data Directory";
Step 2: Specify Input and Output Files
Define the paths for the input MS Project file and the resulting updated file:
String file = dataDir + "ResourceWithExtAttribs.xml"; // Test file with one rsc to update
String resultFile = dataDir + "OutputMPP.mpp"; // File to write test project
Step 3: Load the Project
Load the MS Project file into a Project
object:
Project project = new Project(file);
Step 4: Add a Resource and Set Attributes
Add a new resource to the project and set its attributes such as standard rate, overtime rate, and group:
Resource rsc = project.getResources().add("Rsc");
rsc.set(Rsc.STANDARD_RATE, BigDecimal.valueOf(30));
rsc.set(Rsc.OVERTIME_RATE, BigDecimal.valueOf(45));
rsc.set(Rsc.GROUP, "Workgroup1");
Step 5: Save the Project
Save the updated project with the modified resource data:
project.save(resultFile, SaveFileFormat.Mpp);
Conclusion
In this tutorial, we have demonstrated how to update MS Project resource data using Aspose.Tasks for Java. By following these steps, you can efficiently manipulate resource information in your MS Project files programmatically.
FAQ’s
Q1: Can I update multiple resources in the same project using Aspose.Tasks for Java?
A1: Yes, you can update multiple resources by iterating through them and setting their attributes accordingly.
Q2: Does Aspose.Tasks support other file formats besides MS Project?
A2: Yes, Aspose.Tasks supports various file formats including XML, MPP, and more.
Q3: Is Aspose.Tasks compatible with different versions of Java?
A3: Aspose.Tasks is compatible with Java versions 6 and above.
Q4: Can I perform other operations on MS Project files with Aspose.Tasks?
A4: Yes, you can perform a wide range of operations such as reading, writing, and manipulating tasks, resources, and calendars.
Q5: Where can I find additional help or support for Aspose.Tasks?
A5: You can visit the Aspose.Tasks forum for any assistance or queries.