2012-06-18 2 views
1

Office Interop Word 개체를 사용하여 단어 문서를 생성하는 함수를 작성했습니다. 내 코드는 아래와 같습니다. 내 로컬 시스템에서 제대로 작동합니다. 하지만 윈도우 서버 2003에서 실행하려고하면 작동하지 않습니다. Word.Document wordDoc = wordApp.Documents.Open에서로드를 유지하며 아무 것도하지 않습니다. 너 좀 도와 줄 수있어?Windows 서버 2003에서 워드 문서를 생성하는 방법은 무엇입니까?

private void GenerateEmploymentCertificate() 
{ 
    object Nothing = System.Reflection.Missing.Value; 
    object format = Word.WdSaveFormat.wdFormatDocument; 
    Word.Application wordApp = new Word.ApplicationClass(); 

    object srcFileName = Server.MapPath(ResolveUrl(@"~/HRLetter\Arabia\Templates\Employment Certificate.doc")); 
    Word.Document wordDoc = wordApp.Documents.Open 
    (ref srcFileName, ref format, ref Nothing, ref Nothing, 
    ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, 
    ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, 
    ref Nothing, ref Nothing); 
    try 
    { 

     object bookmarkDate = "Date"; 
     wordDoc.Bookmarks.get_Item(ref bookmarkDate).Select(); 
     wordApp.Selection.Text = string.Format("{0:MM/dd/yyyy}", lblRequestdate.Text); 

     object bookmarkEmployeeName = "EmployeeName"; 
     wordDoc.Bookmarks.get_Item(ref bookmarkEmployeeName).Select(); 
     wordApp.Selection.Text = lblEmployeeName1.Text; 

     object bookmarkCompany = "Company"; 
     wordDoc.Bookmarks.get_Item(ref bookmarkCompany).Select(); 
     wordApp.Selection.Text = lblCompanyName1.Text; 

     object bookmarkJoiningDate = "JoiningDate"; 
     wordDoc.Bookmarks.get_Item(ref bookmarkJoiningDate).Select(); 
     wordApp.Selection.Text = string.Format("{0:MM/dd/yyyy}", lblJoiningDate1.Text); 

     object bookmarkDesignation = "Designation"; 
     wordDoc.Bookmarks.get_Item(ref bookmarkDesignation).Select(); 
     wordApp.Selection.Text = lblDesignation1.Text; 

     string DocName; 
     DocName = string.Format("{0}_employment_certificate", lblRequestNo.Text); 
     hFilename.Value = DocName; 
     wordDoc.SaveAs(Server.MapPath(ResolveUrl(@"~/HRLetter\Arabia\Letters\" + DocName + ".doc"))); 

    } 
    catch (Exception exp) 
    { 
     Session["generalError"] = null; 
     Session["generalError"] = "There was an error at generating the letter. Please send email to [email protected] with this screen shot.<br /><br /><br />Request No:" + lblRequestNo.Text + "<br />Action:Submit<br />" + exp.StackTrace.ToString(); 
     LogManager logHelper = new LogManager(Request.PhysicalApplicationPath.Trim(), "Leave System - Malaysia"); 
     logHelper.LogError("[btnSubmit_Click - ]" + exp.Message + ".StackTrace - " + exp.StackTrace.ToString()); 
     Response.Redirect(ResolveUrl("~/Error/ErrorHandler.aspx")); 
    } 
    finally 
    { 
     // Close wordDoc2 
     wordDoc.Close(ref Nothing, ref Nothing, ref Nothing); 
     if (wordDoc != null) 
     { 
      System.Runtime.InteropServices.Marshal.ReleaseComObject(wordDoc); 
      wordDoc = null; 
     } 
     // close wordApp 
     wordApp.Quit(ref Nothing, ref Nothing, ref Nothing); 
     if (wordApp != null) 
     { 
      System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp); 
      wordApp = null; 
     } 
    } 
    GC.Collect();} 
+0

나는 asp.net 4 및 Windows Server 2003 R2 Standart x64 Edition에서 단어 자동화를 달성하려고합니다. Google에서 검색했지만 해결책을 찾지 못했습니다. 난 다음 스레드에서 솔루션을 시도했지만 아무것도 나를 위해 [말씀 자동화] [1] [Word 2007에서 문서] 작동하지 않습니다 [2] 문제와 그에 대한 해결책이 될 수 무엇 ? 저 좀 도와 주 시겠어요? 감사합니다. [1] : http://social.msdn.microsoft.com/Forums/en-US/netfx64bit/thread/65a355ce-49c1-47f1-8c12-d9cf5f23c53e [2] : HTTP : //social.msdn .microsoft.com/Forums/ko/architecturegeneral/thread/0f5448a7-72ed-4f16-8b87-922b71892e07 –

답변

1

MS Office는 서버 환경에서 실제로 작동하지 않습니다. Even MS says so.

우리는 LibreOffice와 함께 작동 시켰습니다. 우리는 그것을 읽을 수 있습니다 blog

+0

Open Xml 메서드로 작업하게 만들었습니다. –

관련 문제