Ms Project:如何使用 C# 使甘特图专注于整个项目?
Ms Project: How to make Gantt chart focus on entire project using C#?
我正在尝试使用 C# 创建 MPP 文件。
我成功了,但是在完成创建 MPP 文件后我的甘特图有一个小问题我发现甘特图的时间刻度在当前日期所以我滚动到第一个日期时间的任务查找任务的资源和前置任务
我想让文件打开并自动聚焦到甘特图的整个项目。
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);
我正在尝试使用 C# 创建 MPP 文件。
我成功了,但是在完成创建 MPP 文件后我的甘特图有一个小问题我发现甘特图的时间刻度在当前日期所以我滚动到第一个日期时间的任务查找任务的资源和前置任务
我想让文件打开并自动聚焦到甘特图的整个项目。
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);