读取和保存MSProject文件 [英] Reading and Saving MSProject file

查看:141
本文介绍了读取和保存MSProject文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我一直在网上搜索有关如何正确加载和保存Microsoft Project文件的示例代码。在挖掘和一些试验和错误之后,我偶然发现了保存我打开的相同MPP文件的问题。我试着玩这些属性,但无济于事。以下是我以前使用的代码:

Hi, I have been searching online for some sample codes on how to correctly load and save a Microsoft Project file. After digging and some trials and errors, I stumbled upon the problem of saving the same MPP file I opened. I tried playing with the attributes, but to no avail. Here are the codes I used to play with:

object fileName = "C:\\Test.mpp";
object readOnly = false;
object missing = System.Reflection.Missing.Value;

Microsoft.Office.Interop.MSProject.PjMergeType merge = Microsoft.Office.Interop.MSProject.PjMergeType.pjDoNotMerge;

Microsoft.Office.Interop.MSProject.PjPoolOpen pool = Microsoft.Office.Interop.MSProject.PjPoolOpen.pjDoNotOpenPool;

object ignoreReadOnlyRecommended = false;
            
Microsoft.Office.Interop.MSProject.ApplicationClass appclass = new Microsoft.Office.Interop.MSProject.ApplicationClass();

appclass.FileOpen(fileName, readOnly, merge, missing, missing, missing, missing, missing, missing, missing, missing, pool, missing, missing, ignoreReadOnlyRecommended, missing);

appclass.Visible = false;

Microsoft.Office.Interop.MSProject.Project project = appclass.ActiveProject;
            
project.Resources.Add("A", 1);
project.Resources.Add("B", 2);
project.Resources.Add("C", 3);
project.Resources.Add("D", 4);
project.Resources.Add("E", 5);

Microsoft.Office.Interop.MSProject.Task task = project.Tasks.Add("Requirement Collection",missing);

task.Start = "08/1/2007";
task.Finish = "10/25/2007";

task.Assignments.Add(task.ID, 1, missing);
task.Assignments.Add(task.ID, 2, missing);

task.Milestone = true;
task.OutlineLevel = 2;

appclass.FileSave();



当我尝试保存时出现问题。它打开Microsoft Project并提示我保存为。我只是希望它让Microsoft Project脱颖而出并悄然保存。我注意到该文件以只读方式打开,即使我指定它不是以只读方式打开。我认为我可能做错了什么,但我不知道是什么。请指出我做错了什么。



顺便说一下,我使用的是Microsoft Project 12.0对象库。



另外,如何正确地将前任附加到任务?


The problem occurs when I am trying to save. It opens up Microsoft Project and prompt me to save as instead. I just want it to let Microsoft Project out of it and quietly save. I notice that the file is opened as Read-Only even though I specified it to open not as Read-Only. I figure that I might be doing something wrong, but I have no idea what. Please point me what I am doing wrong.

By the way, I am using Microsoft Project 12.0 Object Library.

Also, how do I correctly attach a predecessor to a task?

推荐答案

对我来说工作正常(在Project 10.0中)。我可以找到使其成为SaveAs对话框的唯一方法是,如果源文件仅在第一时间读取
Works OK for me (in Project 10.0). The only way that I could find to make it come up with the SaveAs dialog was if the source file was read only in the first place


在线搜索并在其他目录上测试之后,有用。首先是Windows 7管理员控制干扰程序。此外,打开文件后,我需要关闭它。如果我不关闭文件,项目文件将叠加在任务栏中。



After searching online and testing out on a different directory, it works. It was Windows 7 administrator control interfering with the program in the first place. Also, after opening the file, I need to close it. If I don't close the file, the project file will stack up in the task-bar.

//appclass.FileSave();
appclass.FileClose(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave, missing);


这篇关于读取和保存MSProject文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆