MS Project is a popular project management software, widely used to organize, manage, and track project activities efficiently. It allows creating the tasks, adding resources, allocating tasks to resources, monitoring the progress, and managing budget-related activities. The Gantt chart view is the default view of the project. It lists project tasks and shows their relationship to one another. It also shows the schedule of the project using Gantt bars. In this article, we will learn how to read the Gantt chart of the MS project using Java.
The following topics shall be covered in this article:
- What is Gantt Chart in Microsoft Project
- Java API to Read Gantt Chart of Project
- Read Gantt Chart View and Retrieve Bar Styles
- Read Grid Lines of Gantt Chart View
- Extract Text Style of Gantt Chart View
- Retrieve Progress Lines of Gantt Chart View
- Read Bottom Timescale Tier
- Read Middle Timescale Tier
- Retrieve Top Timescale Tier
What is Gantt Chart in Microsoft Project
A Gantt chart is a type of bar chart that shows the project schedule. It is a graphical representation of project tasks against time and offers a bird’s eye view of the entire project. The Gantt chart view in Microsoft Project shows the following:
- Project schedule
- Time estimates
- Project resources & team members
- Task priorities
- Task dependency
Java API to Read Gantt Chart of Project
For reading the Gantt chart view of a Project from the MPP file, we will be using the Aspose.Tasks for Java API. It allows creating, editing, or manipulating Microsoft Project files programmatically in Java applications. The Project class of the API represents a project. It is the main class exposing various methods to perform different functions. It also allows reading one of the supported project management formats such as MPP, MPT, MPX, and XML. The GanttChartView class of the API represents a Gantt chart view. It exposes various properties and methods to work with the Gantt chart programmatically.
Please either download the JAR of the API or add the following pom.xml configuration in a Maven-based Java application.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-tasks</artifactId>
<version>22.5</version>
<classifier>jdk18</classifier>
</dependency>
Read Gantt Chart View and Retrieve Bar Styles
The GanttBarStyle class of the API represents a bar-style used by MS Project in the Gantt chart view. We can read the Gantt chart view and retrieve the bar styles by following the steps given below:
- Firstly, load the project file using the Project class.
- Next, get the default view from the ViewCollection by its index.
- Then, create an instance of the GanttChartView class and typecast view.
- Optionally, read basic properties and show data.
- After that, get a list of bar styles of the Gantt chart view using the getBarStyles().
- Finally, loop through bar styles as GanttBarStyle class object and show values.
The following code example shows how to read bar styles of the Gantt chart view in Java.
Bar Rounding: true
Show Bar Splits: true
Show Drawings: true
RollUp Gantt Bars: false
Hide Rollup Bars When Summary Expanded: false
Bar Size: 3
Bar Styles count: 40
-----------------------------------------------
Row: 1
Name: Task
ShowFor: null
From:TaskStart
To:TaskFinish
Middle Shape:RectangleBar
Middle Shape Color:java.awt.Color[r=0,g=0,b=255]
Start Shape:NoBarEndShape
End Shape:NoBarEndShape
End Shape Color:java.awt.Color[r=0,g=0,b=0]
-----------------------------------------------
...
Read Grid Lines of Gantt Chart View in Java
The Gridlines class of the API represents grid lines that appear in a Gantt chart view. We can read the grid line’s color, interval, pattern, and type by following the steps given below:
- Firstly, load the project file using the Project class.
- Next, get the default view from the ViewCollection by its index.
- Then, create an instance of the GanttChartView class and typecast view.
- After that, get a list of Grid lines of the Gantt chart view using the getGridlines().
- Finally, loop through grid lines as the Gridlines class object and show values.
The following code example shows how to read grid lines of the Gantt chart view in Java.
Gridlines Count: 14
Gridlines Type: 3
Gridlines Interval: 0
Gridlines NormalColor: java.awt.Color[r=192,g=192,b=192]
Gridlines NormalPattern: Solid
Gridlines IntervalPattern: 0
Gridlines IntervalColor: java.awt.Color[r=192,g=192,b=192]
Extract Text Style of Gantt Chart View in Java
The TextStyle class of the API represents the visual style of the text for an item in a Gantt chart view. We can read the color, background color, font, and font style by following the steps given below:
- Firstly, load the project file using the Project class.
- Next, get the default view from the ViewCollection by its index.
- Then, create an instance of the GanttChartView class and typecast view.
- After that, get a list of text styles of the Gantt chart view using the getTextStyles().
- Finally, initialize the TextStyle class object for the first text style and show values.
The following code example shows how to read text styles of the Gantt chart view in Java.
Text Styles Count: 19
Background Color: java.awt.Color[r=0,g=0,b=0]
Text Color: java.awt.Color[r=0,g=0,b=255]
Font Family: Arial
Font Size: 8.0
Font Style: Regular
Retrieve Progress Lines of Gantt Chart View in Java
The progress lines appear on the Gantt Chart view showing whether tasks are behind, or right on schedule. We can read the various properties of the progress lines by following the steps given below:
- Firstly, load the project file using the Project class.
- Next, get the default view from the ViewCollection by its index.
- Then, create an instance of the GanttChartView class and typecast view.
- After that, get a list of progress lines of the Gantt chart view using the getProgressLines().
- Finally, show progress line attribute values.
The following code example shows how to read progress lines of the Gantt chart view in Java.
Read Bottom Timescale Tier in Java
Timescale shows time units, days, months, calendar year, or fiscal year. There are three timescale tiers in the project view to show the timescale values for each tier such as count, unit, label, alignment, etc. We can read the bottom timescale tier by following the steps given below:
- Firstly, load the project file using the Project class.
- Next, get the default view from the ViewCollection by its index.
- Then, create an instance of the GanttChartView class and typecast view.
- After that, get the settings of the view’s bottom timescale tier using the getBottomTimescaleTier().
- Finally, show bottom timescale tier values.
The following code example shows how to read the bottom timescale tier of the Gantt chart view in Java.
BottomTimescaleTier Count: 2
BottomTimescaleTier Unit: Days
BottomTimescaleTier UsesFiscalYear: true
BottomTimescaleTier Alignment: Center
BottomTimescaleTier ShowTicks: true
BottomTimescaleTier Label: DayOfMonthDd
Read Middle Timescale Tier in Java
Similarly, we can read the middle timescale tier by following the steps mentioned earlier. However, we will get the settings of the view’s middle timescale tier using the getMiddleTimescaleTier() in step 4.
The following code example shows how to read the middle timescale tier of the Gantt chart view in Java.
MiddleTimescaleTier.Count: 1
TimescaleUnit.Weeks: Months
MiddleTimescaleTier.Alignment: Center
MiddleTimescaleTier.ShowTicks: true
MiddleTimescaleTier.Label: MonthMmmmYyyy
Retrieve Top Timescale Tier in Java
We can also read the top timescale tier by following the steps mentioned earlier. However, we will get the settings of the view’s top timescale tier using the getTopTimescaleTier() in step 4.
The following code example shows how to read the top timescale tier of the Gantt chart view in Java.
TopTimescaleTier Unit: Quarters
TopTimescaleTier UsesFiscalYear: true
TopTimescaleTier Alignment: Center
TopTimescaleTier ShowTicks: true
TopTimescaleTier Label: QuarterQtrQYyyy
Get a Free License
You can get a free temporary license to try the library without evaluation limitations.
Conclusion
In this article, we have learned how to
- read the Gantt chart view programmatically in Java;
- extract Gantt chart view’s bar styles and text style;
- retrieve grid lines and progress lines of the Gantt chart view;
- read timescale units of Gantt chart view using Java.
Besides, you can learn more about Aspose.Tasks for Java API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.