2014-10-07 5 views
2

단어 파일에서 텍스트를 추출하는 데 "netoffice"라이브러리를 사용하고 있습니다. 이것은 자동화 된 프로세스 여야합니다.암호로 보호 된 단어 파일 검색

그러나 단어 파일이 암호로 보호되어 있으면 경고 창이 표시되어 사용자가 암호를 입력해야합니다. 이것은 자동 프로세스이므로 사용자가 암호를 입력하지 않고 프로그램이 여기서 중지됩니다.

단어 파일이 "netoffice"로 암호로 보호되어 있는지 어떻게 알 수 있습니까? 이것이 불가능할 경우 어떻게 경고 창을 표시하지 않도록 설정할 수 있습니까?

DisplayAlerts를 WdAlertLevel.wdAlertsNone으로 설정하려고했지만 작동하지 않습니다.

답변

1

다음 코드 조각은 암호로 보호 된 파일을 건너 뛰 도움이 될 것입니다 : 이전과

 int iFilesWithPassword = 0; 
     Factory.Initialize(); 
     Application wordApplication = new NetOffice.WordApi.Application(); 

     try 
     { 
      // Attempt to open existing document. If document is not password protected then 
      // passwordDocument parameter is simply ignored. If document is password protected 
      // then an error is thrown and caught by the catch clause the follows, unless 
      // password is equal to "#[email protected]!"!        
      Document newDocument = wordApplication.Documents.Open(@"C:\Users\Giorgos\Desktop\myNextFile.doc", 
                    confirmConversions: false, 
                    addToRecentFiles: false, 
                    readOnly: false, 
                    passwordDocument: "#[email protected]!"); 



      // read text of document 
      string text = newDocument.Content.Text; 
     } 
     catch(Exception e) 
     { 
      Exception inner = e.InnerException; 

      if (inner != null && inner.InnerException != null) 
      { 
       inner = inner.InnerException; 
       string sErrorMessage = inner.Message; 

       if (sErrorMessage.Contains("The password is incorrect.")) 
       { 
        iFilesWithPassword++; 
       } 
      } 

     } 
     finally 
     { 
      // close word and dispose reference 
      wordApplication.Quit(); 
      wordApplication.Dispose(); 
     } 
+0

같은, 경고 창이 표시됩니다. – Programmer

+0

VS2012에서 Net0ffice.dll, v1.6과 함께 .NET Framework 4.0을 사용하여 콘솔 응용 프로그램을 만들었습니다. passwordDocument 인수를 생략하면 암호 프롬프트 대화 상자도 표시됩니다. passwordDocument 인수를 추가하면 대화 상자가 표시되지 않고 예외가 발생합니다. –

+1

이 답변의 수락 된 응답 상태에서 [programmer] (http://stackoverflow.com/users/2096420)의 주석을 삭제해야하는지 확신 할 수 없지만이 스크립트의 VBS 버전이 [giorgos -betsos] (http://stackoverflow.com/users/2149718)가 제안합니다. – user66001

관련 문제