.NET读取Project 2007 MPP项目文件

Project文件读取:

方法1:Microsoft.Project.OLEDB.11.0

string strConn = "Provider=Microsoft.Project.OLEDB.11.0;Project Name=" + fileName;
DataSet ds = new DataSet();
using (OleDbConnection conn = new OleDbConnection(strConn))
{
conn.Open();
string[] tablesName = new string[] { "Assignments", "Tasks", "Resource" };
for (int k = 0; k < tablesName.Length; k++)
{
string strTableName = tablesName[k];
string str = "select * from " + strTableName;
OleDbDataAdapter da = new OleDbDataAdapter(str, conn);
da.Fill(ds, strTableName.ToLower());
da.Dispose();
}
conn.Close();
conn.Dispose();
}
return ds;

方法2:Microsoft.Office.Interop.MSProject

Object missing = Type.Missing;
ApplicationClass prj = new ApplicationClass();
//打开mpp文件
prj.FileOpen(fileName, true, missing, missing, missing, missing, missing, missing, missing,
missing, missing, PjPoolOpen.pjPoolReadOnly, missing, missing, missing, missing);
return prj.Projects;
以上两个方法都需要安装Microsoft.Project

方法3:mpxj

ProjectReader reader = ProjectReaderUtility.getProjectReader(fileName);
ProjectFile projectFile = reader.read(fileName);
List tasks = projectFile.getAllTasks();
for (int i = 0; i < tasks.size(); i++)
{
Task task = tasks.get(i) as Task;
}

上一篇:lambda,map,filter,reduce


下一篇:Chapter 1. Hello, Perl/Tk