Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / WPF
Tip/Trick

MPP Viewer

Rate me:
Please Sign up or sign in to vote.
4.75/5 (13 votes)
15 Jun 2011CPOL3 min read 103K   4.1K   41   20
MPP Viewer is a simple viewer for Microsoft Project files. I works well with 2000/2003/2007 file formats.

Introduction

MPP Viewer is a simple viewer for Microsoft Project files. It allows you to perform open, export to Excel. It works fine with Project 2000/2003/2007 files. I have used MPXJ open source library to read project files. More details of the same are available from http://mpxj.sourceforge.net/. You will need to download and add the reference to mpxj library to run MPP Viewer. I could not upload all the referenced files due to size constraint. MPXJ distribution also contains a native .NET DLL version of MPXJ and its library dependencies.

I have published MPP Viewer on sourceforge.net at http://sourceforge.net/projects/mppviewer. You can download the latest version of MPP Viewer executable and source from the above link. I am yet to upload the source code into Sourceforge.net. I am planning to do this soon.

I have used TreeListView control shared here. It's a very clean implementation of WPF Tree List view and much easier to use.

Mpp_Viewer_-_beta.JPG - Click to enlarge image

MPP Viewer Allows You To Do the Following

  1. View tasks in hierarchy
  2. View details of the task
  3. View resources with associated tasks
  4. View details of resources
  5. Export the project task and resource information to
  6. Allows multiple project documents to be open at the same time 
  7. Allows printing tasks in the project file
  8. Filter tasks by Completed, Not Complete, Completing Today, Completing today
  9. Highlight tasks not complete passed due dateView Tasks with hierarchy
  10. Supports Microsoft Project 2000, 2003, 2007

I have to create set of class / wrapper classes in .NET to leverage databinding and other capabilities in .NET and WPF.

I have not validated with other versions of Microsoft Project. MPXJ at sourceforge claims it works with 98 and 2010 too.

Class Diagram

I have tried to follow MVVM throughout. You can read more about MVVM at:

MppViewer/MPP_Viewer.png

Points of Interest

To perform Export to Excel, I have used Open XML SDK 2.0. I did not use the SDK tool to generate and use the template. So the Excel that is created is not nicely formatted. I have created a re-usable class that can export dataset into Excel file. Each DataTable is exported on to a separate file. Export functionality is performed using the following code.

Step 1: Create the SpreadsheetDocument, this represents an Excel document package.

C#
private void GenerateExcelDocument()
{
	using (SpreadsheetDocument spreadsheetDocument =
	SpreadsheetDocument.Create(FilePath, SpreadsheetDocumentType.Workbook))
	{
		InitilizeParts(spreadsheetDocument);
	}
}

Step 2: Create the main WorkbookPart that contains the worksheets.

C#
private void InitilizeParts(SpreadsheetDocument package)
{
	WorkbookPart workbookPart = package.AddWorkbookPart();
	workbookPart.Workbook = new Workbook();

	Sheets sheets = new Sheets();

	for (int i = 0; i < Data.Tables.Count; i++)
	{
		WorksheetPart worksheetPart = workbookPart.AddNewPart<worksheetpart>();
		InitilizeParts(worksheetPart, Data.Tables[i]);

		Sheet sheet =
		new Sheet()
		{
			Name = Data.Tables[i].TableName,
			SheetId = sheets.HasChildren ? 
			sheets.Elements<sheet>().Select
				(s => s.SheetId.Value).Max() + 1 : 1,
			Id = workbookPart.GetIdOfPart(worksheetPart)
		};

		sheets.Append(sheet);
	}

	workbookPart.Workbook.Append(sheets);
	workbookPart.Workbook.Save();
}

Step 3: Create a blank Worksheet and add it to the WorkbookPart.

Step 4: Create a blank Sheet and add it to the WorkbookPart. Id of the Sheet should be same as that of the Worksheet to create a relationship between them.

C#
private void InitilizeParts(WorksheetPart worksheetPart, DataTable dataTable)
{
	Worksheet worksheet = new Worksheet();

	SheetData sheetData = new SheetData();

	Row header = new Row();
	header.RowIndex = (UInt32)1;

	foreach (DataColumn column in dataTable.Columns)
	{
		Cell headerCell = InitilizeParts
		(column.ColumnName, dataTable.Columns.IndexOf(column) + 1, 1);

		header.AppendChild(headerCell);
	}
	sheetData.AppendChild(header);

	DataRow contentRow;
	for (int i = 0; i < dataTable.Rows.Count; i++)
	{
		contentRow = dataTable.Rows[i];
		sheetData.AppendChild(InitilizeParts(contentRow, i + 2));
	}

	worksheet.Append(sheetData);
	worksheetPart.Worksheet = worksheet;
}

Step 5: Create SheetData for each Worksheet.

Step 6: Create Rows and Cells into SheetData with appropriate CellReference.

C#
private Row InitilizeParts(DataRow dataRow, int rowIndex)
{
	Row row = new Row { RowIndex = (UInt32)rowIndex };

	for (int i = 0; i < dataRow.Table.Columns.Count; i++)
	{
		Cell dataCell = InitilizeParts(dataRow[i], i + 1, rowIndex);
		row.AppendChild(dataCell);
	}

	return row;
}

private Cell InitilizeParts(object cellValue, int columnIndex, int rowIndex)
{
	Cell cell = new Cell();
	cell.DataType = CellValues.InlineString;
	cell.CellReference = getExcelCellReference(columnIndex) + rowIndex;

	InlineString inlineString = new InlineString();
	Text t = new Text();

	t.Text = cellValue.ToString();
	inlineString.AppendChild(t);
	cell.AppendChild(inlineString);

	return cell;
}

ComboBox does not implement command interface. One of the options is to develop a new combobox extending the ComboBox and implementing the ICommandSource interface. The other alternate is to use Interaction from System.Windows.Interactivity namespace. This assembly is available with BlendSDK. It makes it very simple to attach commands to SelectionChange event.

XML
<ComboBox Name="filterComboBox" VerticalAlignment="Center" >
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectionChanged">
            <i:InvokeCommandAction Command="{Binding FilterChangedCommand}"
		CommandParameter="{Binding Path=SelectedItem.Content, 
		ElementName=filterComboBox}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <ComboBoxItem Content="All" IsSelected="True" />
    <ComboBoxItem Content="Completed" />
    <ComboBoxItem Content="In Complete" />
    <ComboBoxItem Content="To Complete Today" />
    <ComboBoxItem Content="To Complete Tomorrow" />
</ComboBox>

Some of the items I am looking to add in future are:

  1. Viewer for Gantt Chart
  2. Well formatted Excel generated from the tool

History

  • 15th June, 2011: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionExport to excel option causes an exception Pin
Member 150360025-Jan-21 21:12
Member 150360025-Jan-21 21:12 
QuestionAny way to edit mpp file from viewer Pin
Member 1179733417-Feb-18 10:18
Member 1179733417-Feb-18 10:18 
QuestionGantt support Pin
Roman M. Kudryavtsev19-Jul-16 4:34
Roman M. Kudryavtsev19-Jul-16 4:34 
QuestionWriting into MPP file using MPXJ - Urgent Pin
ksbaboo20-Nov-12 16:23
ksbaboo20-Nov-12 16:23 
AnswerRe: Writing into MPP file using MPXJ - Urgent Pin
Vivek Krishnamurthy23-Nov-12 18:15
Vivek Krishnamurthy23-Nov-12 18:15 
GeneralRe: Writing into MPP file using MPXJ - Urgent Pin
ksbaboo28-Nov-12 19:49
ksbaboo28-Nov-12 19:49 
GeneralRe: Writing into MPP file using MPXJ - Urgent Pin
Vivek Krishnamurthy6-Dec-12 4:24
Vivek Krishnamurthy6-Dec-12 4:24 
GeneralRe: Writing into MPP file using MPXJ - Urgent Pin
ksbaboo13-Dec-12 17:21
ksbaboo13-Dec-12 17:21 
GeneralRe: Writing into MPP file using MPXJ - Urgent Pin
Vivek Krishnamurthy15-Dec-12 6:59
Vivek Krishnamurthy15-Dec-12 6:59 
QuestionWhat did you use to get the Class diagram you shared in this article? Pin
VC Sekhar Parepalli22-Oct-12 16:57
VC Sekhar Parepalli22-Oct-12 16:57 
AnswerRe: What did you use to get the Class diagram you shared in this article? Pin
Vivek Krishnamurthy22-Oct-12 21:37
Vivek Krishnamurthy22-Oct-12 21:37 
QuestionGantt Diagram Pin
Member 477326826-Sep-12 19:48
Member 477326826-Sep-12 19:48 
AnswerRe: Gantt Diagram Pin
Vivek Krishnamurthy29-Sep-12 8:54
Vivek Krishnamurthy29-Sep-12 8:54 
GeneralRe: Gantt Diagram Pin
Member 477326830-Sep-12 21:34
Member 477326830-Sep-12 21:34 
GeneralRe: Gantt Diagram Pin
Vivek Krishnamurthy5-Oct-12 1:09
Vivek Krishnamurthy5-Oct-12 1:09 
GeneralRe: Gantt Diagram Pin
Member 47732687-Oct-12 18:39
Member 47732687-Oct-12 18:39 
GeneralRe: Gantt Diagram Pin
Vivek Krishnamurthy7-Oct-12 20:42
Vivek Krishnamurthy7-Oct-12 20:42 
GeneralAwesome work man. Pin
Sourabh Khatri11-Aug-11 19:11
Sourabh Khatri11-Aug-11 19:11 
GeneralMy vote of 5 Pin
OlegKrivtsov15-Jun-11 16:42
OlegKrivtsov15-Jun-11 16:42 
GeneralRe: My vote of 5 Pin
Vivek Krishnamurthy24-Jun-11 2:15
Vivek Krishnamurthy24-Jun-11 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.