-
我正在尝试使用C#创建一个MPP文件。
-
我成功了,但在完成创建MPP文件后,甘特图出现了一个小问题。我发现甘特图在当前日期的时间刻度,所以我滚动到第一个日期时间的任务,以查找资源和任务的前任
-
我想打开文件,并自动将焦点集中在甘特图的整个项目上。
ms项目的命名空间为:
使用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);