c# 读取project 内容代码demo

1.安装

安装office,需要使用其中的dll,或者直接使用下面的dll

 

 

2.引用

添加此dll引用到项目中,并且嵌入互操作类型设置为false,否则代码中使用MSProject.ApplicationClass 会报错

 

 

 

3.读取demo

  public  ActionResult Import(HttpPostedFileBase file)

        {

            Microsoft.Office.Interop.MSProject.ApplicationClass prj = new MSProject.ApplicationClass();

            string prjFileName = file.FileName;

            prjFileName= @"C:\Users\Administrator\Desktop\" + prjFileName + "";

            prj.FileOpen(prjFileName, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, MSProject.PjPoolOpen.pjPoolReadOnly, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            foreach (MSProject.Project proj in prj.Projects)

            {

                foreach (MSProject.Task task in proj.Tasks)

                {

                    string str = "";

 

                    int iTaskLevel = task.OutlineLevel;

                    for (int j = 0; j < iTaskLevel; j++)

                    {

                        str += "---";

                    }

                    Response.Write(str + task.Name + "++++++" + task.Start + "+++++" + task.Finish + task.ResourceNames.ToString() + "<br/>");

                }

            }

 

            prj.FileClose(MSProject.PjSaveType.pjDoNotSave, false);

            prj.Quit(MSProject.PjSaveType.pjDoNotSave);

 

            return Json("");

        }

posted @ 2023-10-25 14:08  keke..lele  阅读(57)  评论(0编辑  收藏  举报