문제

I have an application in Asp .Net Mvc3, i am using the mpxj library for to generate a project file (with extension mpx). But this file not contain dates for Tasks, then i want to open the file with Ms Project and then save with the new format (Ms project create Dates for tasks). Detail is that i want to do it automatically. Is it possible? What is the best way?

도움이 되었습니까?

해결책

I know that interop MsOffice in Asp.NET not is recommended http://support.microsoft.com/kb/257757. But the need to automatically calculate dates, I am handling errors, and I am using MsProject Interop. This is my code:

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

app.FileOpenEx(
        Server.MapPath("") + "\\sample.mpx",
        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;

app.CalculateAll(); //Para calcular las fechas

app.FileSaveAs(Server.MapPath("") + "\\sample.mpp",PjFileFormat.pjMPP, Type.Missing, Type.Missing,Type.Missing,           Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing);

다른 팁

Import library Microsoft.Office.Interop.MSProject.

See my code from an ASP.NET Web Forms. You can do the same with any version of ASP; you can also do it with ASP.NET Core, but that changes some small things.

  1. If you noticed, I saved my file in path c:\temp

  2. I take the file from the front as a variable fu_upload and make my process, then saved file and open it for read.

     ApplicationClass appclass = new ApplicationClass();
    
     object oMissing = System.Reflection.Missing.Value;
     object mppfile = @"c:\Temp";
     if (fu_Upload.PostedFile.FileName.Contains(@"\"))
         mppfile += fu_Upload.PostedFile.FileName.Substring(fu_Upload.PostedFile.FileName.LastIndexOf("\\"), fu_Upload.PostedFile.FileName.Length - fu_Upload.PostedFile.FileName.LastIndexOf('\\'));// fu_Upload.PostedFiles[0].FileName;
     else
         mppfile += @"\" + fu_Upload.PostedFile.FileName;
     fu_Upload.PostedFile.SaveAs(mppfile.ToString());
     object oFormat = "MSProject.mpp";
     object oReadOnly = true;
    
     PathFile = mppfile.ToString();
    
     UploadFileToFileSpacePage(fu_Upload, PathFile);
    
     appclass.DisplayAlerts = false;
     //    var projectdoc ;
     appclass.FileOpen(mppfile, oReadOnly, Microsoft.Office.Interop.MSProject.PjMergeType.pjDoNotMerge, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oFormat, oMissing, Microsoft.Office.Interop.MSProject.PjPoolOpen.pjPoolReadOnly, oMissing, oMissing, oMissing, oMissing);
    
     Microsoft.Office.Interop.MSProject.Project project = appclass.ActiveProject;
    
     return project;
    
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top