另外,为了将其与Project整合到一起,我在网上找了很久,终于找到了一个VSTO Add-in的示例程序(网上关于Office开发的都集中在Word,Excel和Outlook上,Project的资料简直就是凤毛麟角,而且由于它的名称叫Project,还会有很多无关信息;微软也真是的,连Project的PIA都提供了,不msdn挖了个底朝天都找不着Project的Object Model,只有个过时的vb6.0的)。
现在看看程序:
应用命名空间:
using System.Data.OleDb;
关键代码:private void mnuFileOpen_Click(object sender, EventArgs e)
{
OpenFileDialog frmOpenFile = new OpenFileDialog();
frmOpenFile.Filter = "Project文件 (*.mpp)|*.mpp|All files (*.*)|*.*";
frmOpenFile.FilterIndex = 1;
frmOpenFile.RestoreDirectory = true;
string path = "";
if (frmOpenFile.ShowDialog() == DialogResult.OK)
path = frmOpenFile.FileName;
string connString = "Provider=Microsoft.Project.OLEDB.11.0;Project Name=" + path;
conn = new OleDbConnection(connString);
conn.Open();
string statment = "SELECT AssignmentTaskID, AssignmentTaskName FROM Assignments WHERE TaskUniqueID > 0 ORDER BY AssignmentTaskID ASC";
adapter = new OleDbDataAdapter(statment, conn);
dataSet = new DataSet();
adapter.Fill(dataSet, "Assignments");
dgvMain.DataSource = dataSet;
dgvMain.DataMember = "Assignments";
}
{
OpenFileDialog frmOpenFile = new OpenFileDialog();
frmOpenFile.Filter = "Project文件 (*.mpp)|*.mpp|All files (*.*)|*.*";
frmOpenFile.FilterIndex = 1;
frmOpenFile.RestoreDirectory = true;
string path = "";
if (frmOpenFile.ShowDialog() == DialogResult.OK)
path = frmOpenFile.FileName;
string connString = "Provider=Microsoft.Project.OLEDB.11.0;Project Name=" + path;
conn = new OleDbConnection(connString);
conn.Open();
string statment = "SELECT AssignmentTaskID, AssignmentTaskName FROM Assignments WHERE TaskUniqueID > 0 ORDER BY AssignmentTaskID ASC";
adapter = new OleDbDataAdapter(statment, conn);
dataSet = new DataSet();
adapter.Fill(dataSet, "Assignments");
dgvMain.DataSource = dataSet;
dgvMain.DataMember = "Assignments";
}
源程序文件
另有一文是写读取mpp文件数据的SQL语句,题目是“如何从Project数据库中读取mpp文件中自定义域以及自定义大纲代码”,可以看看
现在还要看看mpp文件的xml格式是怎样的,才能生成新的Project文件