简体   繁体   English

如何使用C#.net编辑MS Project的TimescaleStart

[英]how to edit TimescaleStart of MS Project Using C#.net

I have a requirement to modify the ms project file (.mpp) using C#.net. 我需要使用C#.net修改ms项目文件(.mpp)。

I have done with all the things, the only thing remaining is to modify the TimescaleStart date of MPP file using C#.net. 我已经做完所有事情,剩下的唯一事情就是使用C#.net修改MPP文件的TimescaleStart日期。 I need to set the user defined date. 我需要设置用户定义的日期。

How can i do that? 我怎样才能做到这一点?

Following is my code: 以下是我的代码:

Microsoft.Office.Interop.MSProject.Application app = new Microsoft.Office.Interop.MSProject.Application();
app.DisplayAlerts = false;
app.AskToUpdateLinks = false;


app.FileOpenEx(
strFilePath + "test.mpp",
false,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
PjPoolOpen.pjPoolReadWrite, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Microsoft.Office.Interop.MSProject.Project pj = app.ActiveProject;

object objDate = dt.Date;
app.TimescaleStart =   objDate;

Got Error as 错误为

Type mismatch. 类型不匹配。 (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) (来自HRESULT的异常:0x80020005(DISP_E_TYPEMISMATCH))

on Following line: 在以下行中:

app.TimescaleStart =   objDate;

TimescaleStart is a read-only property which returns the date that the timescale starts in the current view. TimescaleStart是一个只读属性,它返回时间刻度在当前视图中的开始日期。

If you want to scroll the view so that it starts at a certain date, find a task with a start date on or close to your target date, select it and invoke the GotoTaskDates method of the application object. 如果要滚动视图以使其在某个日期开始,请找到一个开始日期在目标日期或接近目标日期的任务,选择它并调用应用程序对象的GotoTaskDates方法。 For example: 例如:

 app.Find "Start", "is greater than or equal to", "1/1/2014", Type.Missing, Type.Missing, Type.Missing, Type.Missing
 app.GotoTaskDates

Update: 更新:

If you are using Project 2010 or later, you can also use this method: 如果您使用的是Project 2010或更高版本,则还可以使用以下方法:

app.PanZoomPanTo (objDate)

Could it be that you're actually trying to change the project start date? 可能是您实际上要更改项目的开始日期吗?

If that's the case, try using the "ProjectMove" method. 如果是这种情况,请尝试使用“ ProjectMove”方法。 reference here and here . 在这里这里参考。

If you really really want to change TimescaleStart, it looks like you are out of luck. 如果您真的要更改TimescaleStart, 则看起来很不走运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM