如何在C#

时间:2015-12-18 11:05:16

标签: c#-4.0 mpxj mpp

我有一个带有ProjectTas的ProjectInfo的c#对象,现在如何将这些projectTasks添加到'net.sf.mpxj.Task任务'中C#

当我为net.sf.mpxj.Task创建新对象时,它显示错误'类型net.sf.mpxj.Task没有定义构造函数',所以它不能创建新对象,那怎么能我添加了projectTasks。

以下是不起作用的示例代码:

     List<net.sf.mpxj.Task> tasks=new List<net.sf.mpxj.Task>();

            foreach (var pTask in projectInfo.ProjectTasks)
            {

                net.sf.mpxj.Task task = new net.sf.mpxj.Task();

                        task.TaskId=ptask.TaskId;
                        task.Name = pTask.TaskName;
                        task.Notes = pTask.Description;
                         task.Start=pTask.EstimatedStartDate.ToJavaDate();
                         task.Finish  = pTask.EstimatedEndDate.ToJavaDate();
                        task.Estimated = true;
                        task.Priority = null;
                        task.Type = null;

                    tasks.Add(task);

            }

提前感谢。

2 个答案:

答案 0 :(得分:0)

概览.MPP,.MPX文件格式

http://mpxj.sourceforge.net/howto-start.html

要写入.MPX文件格式的示例代码

https://iniy.org/?p=337

答案 1 :(得分:0)

你没有正确地创建MPXJ对象。请按照以下代码创建MPXJ任务。在这里,我正在创建MS Project的xml格式的MSPDI文件。

    ProjectFile project = new ProjectFile();

    foreach (var pTask in projectInfo.ProjectTasks)
    {
        Task task = project.AddTask();
        task.Name = pTask.TaskName;
        task.Notes = pTask.Description;
        task.Start=pTask.EstimatedStartDate.ToJavaDate();
        task.Finish  = pTask.EstimatedEndDate.ToJavaDate();
        task.Estimated = true;
        task.Priority = null;
        task.Type = null;
    }

    TaskContainer taskCon = project.AllTasks;
    if (taskCon.Size() >= 1)
    {
        java.io.OutputStream outs = null;
        try
        {
            // string serverPath = Server.MapPath(fileName);
            if (System.IO.File.Exists(fullFileName))
            {
                System.IO.File.Delete(fullFileName);
            }
            MSPDIWriter writer = new MSPDIWriter();
            outs = new java.io.FileOutputStream(fullFileName);
            writer.Write(project, outs);
            outs.close();

            if (System.IO.File.Exists(fullFileName))
            {
                string fileName = "ProjectTask.xml";
                WebClient client = new WebClient();
                HttpResponse response = HttpContext.Current.Response;
                response.Clear();
                response.ClearContent();
                response.ClearHeaders();
                response.Buffer = true;
                response.ContentType = "Application/msproject";
                response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
                byte[] data = client.DownloadData(fullFileName);
                response.BinaryWrite(data);
                Response.End();
            }
        }
        catch (System.Exception ex)
        {

        }
        finally
        {
            if (outs != null)
            outs.close();
        }
    }   

我做了很好的研究。如果需要更多帮助,请告诉我。