Ms Project:如何使用 C# 使甘特图专注于整个项目?

Ms Project: How to make Gantt chart focus on entire project using C#?

ms- 项目的命名空间是:

using Microsoft.Office.Interop.MSProject;

    static void Main(string[] args)
    {
        //connect to API 
        var srv = new PMSgatewayClient();

        var projectuid = Guid.Parse("54d5bc97-19dd-e911-8102-00155d6b1204");

        //Get project from database
        var ProjectData = srv.Project_Get_Details(projectuid, Guid.Empty, false, false, Guid.Empty, App_Code.BasicClasses.BasicData.CurrentUser.Id, null, out ErrorCode, out ErorMessage);

        object missing = System.Reflection.Missing.Value;

        //Create the Application object to interact with MS project
        Microsoft.Office.Interop.MSProject.Application appclass = new Application();
        appclass.Projects.Add(false, missing, missing);

        //Get the name of project from database
        string fileName = ProjectData.BasicInfo.DisplayName + DateTime.Now.ToString("yyyy MM mm ss ").Trim();

        //Create file in folder call temp with the name of project 
        appclass.ActiveProject.SaveAs($"{Server.MapPath("~/Temp")}/{fileName}.mpp", PjFileFormat.pjMPP, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

        //Get the active project in the file
        Project project = appclass.ActiveProject;

        Microsoft.Office.Interop.MSProject.Resources resources = project.Resources;

        //We want to go through all the elements in the list
        Tasks tasks = project.Tasks; 

        // here i'm trying to make the Gantt chart focus on time scale of the project or focus on entire project
        project.LevelEntireProject = true;
        tasks.Application.ZoomTimescale("Days", true, false, false);

    }

如果你想让整个项目在甘特图中可见,可以这样用:

appclass.ZoomTimescale(Entire: true);