C # operation mpp file code reference

Source: Internet
Author: User

The Code is as follows:

Using System; using System. collections. generic; using System. text; using Microsoft. office. interop. MSProject; namespace ConsoleApplication {class Program {static void Main (string [] args) {Program pro = new Program (); pro. readMpp (); // pro. callMacro (); // pro. createMpp ();} // call the macro public void callMacro () {Object missing = Type defined in mpp. missing; ApplicationClass prj = new ApplicationClass (); // open the mpp file prj. fileOpen ("C:/Documents ents and Settings/Administrator/My Documents ents/test. mpp ", false, missing, PjPoolOpen. pjPoolReadWrite, missing, and missing); // The call name is testMacro prj. macro ("testMacro"); // close, but do not save mpp prj. fileClose (PjSaveType. pjDoNotSave, false); prj. quit (PjSaveType. pjDoNotSave);} public void readMpp () {Object missing = Type. missing; ApplicationClass prj = new ApplicationClass (); prj. fileOpen ("D:/test. mpp ", false, missing, PjPoolOpen. pjPoolReadWrite, missing, missing); foreach (Project proj in prj. projects) {foreach (Task task in proj. tasks) {System. console. writeLine ("|" + task. name + "|" + task. uniqueID + "|" + task. resourceNames + "|") ;}} prj. fileClose (PjSaveType. pjSave, false); prj. quit (PjSaveType. pjSave); System. console. read ();} public void createMpp () {Object missing = Type. missing; ApplicationClass prj = new ApplicationClass (); PjFileFormat format = PjFileFormat. pjMPP; // format defines prj. visible = true; prj. fileNew (Type. missing, Type. missing, Type. missing, false); Project myProject = prj. activeProject; Task task = null; task = myProject. tasks. add ("zhi", 1); task. start = "2008-8-1"; task. finish = "2008-8-18"; task. setField (PjField. pjTaskNotes, "Task1"); task = null; task = myProject. tasks. add ("wenzhixing", 2); task. start = "2008-8-8"; task. finish = "2008-8-28"; task. actualStart = ""; task. actualFinish = ""; task. outlineLevel = 2; task. setField (PjField. pjTaskResourceNames, "wenzhi"); task = null; task = myProject. tasks. add ("wen", 3); task. start = "2008-8-11"; task. finish = "2008-8-18"; task. setField (PjField. pjTaskNotes, "Task2"); task. notes + = "hehe"; task. outlineLevel = 1; task = null; task = myProject. tasks. add ("wen", 4); task. start = "2008-8-18"; task. finish = "2008-8-28"; task. outlineLevel = 2; task. setField (PjField. pjTaskResourceNames, "wenzhi"); prj. fileSaveAs ("C:/Documents and Settings/Administrator/My Documents/mjm. mpp ", format, missing, false, missing, PjPoolOpen. pjPoolReadWrite, missing, missing );}}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.