C# 新建project 使用ApplicationClass prj = new ApplicationClass(); 报如下错误System.InvalidCastException:“无法将类型为“System.__ComObject”的对象强制转换为类型“Microsoft.Office.Interop.MSProject.ApplicationClass”。
String value0 = this.dataGridView1.Rows[rowindex].Cells[0].Value.ToString();
String value1 = this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
MessageBox.Show("第0列的值:{0};第一列的值:{1};第二列的值:{2}", value0 + "====" + value1);
String FileName = "C:/temp/XXXXXA项目研制/XXXXXA项目研制.mpp";
// System.Diagnostics.Process.Start(FileName).WaitForExit();
Object missing = Type.Missing;
//Microsoft.Office.Interop.MSProject.ApplicationClass prj = new Microsoft.Office.Interop.MSProject.ApplicationClass();
Microsoft.Office.Interop.MSProject.Application prj = new Microsoft.Office.Interop.MSProject.Application();
string strmpp = "";
prj.FileOpen(FileName,
false, missing, missing, missing, missing, missing, missing, missing,
missing, missing, PjPoolOpen.pjPoolReadWrite, missing, missing, missing, missing);
MessageBox.Show("读取XXXXXA项目研制.mpp=01===》", strmpp);
foreach (Project proj in prj.Projects)
{
foreach (Microsoft.Office.Interop.MSProject.Task task in proj.Tasks)
{
if (task == null)
continue;
strmpp += "任务名称:" + task.Name + "," + task.UniqueID + ",资源名称:" + task.ResourceNames + "\r\n";//用ajax来请求的时候,此格式非json格式,会报错
strmpp += "任务名称:" + task.Name + "," + task.UniqueID + ",资源名称:" + task.ResourceNames;//正确方法
}
}
prj.FileClose(PjSaveType.pjSave, false);//关闭
prj.Quit(PjSaveType.pjSave);//关闭
MessageBox.Show("读取XXXXXA项目研制.mpp==02==》", strmpp);