2016-09-28 11 views
2

안녕하십니까 (아르헨티나 시간) 안녕하십니까. 클라이언트의 일부 요구 사항에 따라 시스템에서 단어 문서 형식의 프로젝트를 수신했습니다. 내가받는 워드 문서는 .doc에 있으며 다른 형식이나 내부 디자인으로 내보내거나 작성한 워드 문서는 .docx입니다. 핵심은 Office12 어셈블리와 함께 사용되는 동일한 코드이지만 Office15 인 새 어셈블리를 추가하면 충돌합니다. Range.InsertParagraphAfter()를 사용할 때의 COM 예외

내가 proyect의 비중을 사용하고 샘플 코드

는 유동 충돌 여기서 다음

public void Prueba() 
     { 
      // Open word and a docx file 
      var wordApplication = new Application() { Visible = false }; 
      string [email protected]"<Path>" ; 
      string strNombreArchivo = "<Name of the doc>.doc"; 
      string strddd = "Foo.docx"; 
      var docOriginal = wordApplication.Documents.Open(strPath+strNombreArchivo, ReadOnly: true); 
      //var docddd = wordApplication.Documents.Open(strPath + strddd, ReadOnly: false); 
      var docNuevo = wordApplication.Documents.Add(DocumentType: WdDocumentType.wdTypeDocument); 



      docOriginal.Content.Copy(); 
      docNuevo.Content.Paste(); 
      var docAUsar = docNuevo; 




      Range searchRange = docAUsar.Range(); 
      searchRange.Find.ClearFormatting(); 
      int nextSearchStart = searchRange.Start; 
      searchRange.Start = nextSearchStart; 
      Paragraph ParagraphParrafo = searchRange.Paragraphs.First; 
      nextSearchStart = ParagraphParrafo.Range.End; 
      String titleText = ParagraphParrafo.Range.Text; 

      try 
      { 
       // This is the point where the code crashes. 
       searchRange.InsertParagraphAfter(); 
       docAUsar.Save(); 
      } 
      catch (Exception e) 
      { 
       MessageBox.Show(e.ToString()); 
      } 

      // Close word 
      wordApplication.Quit(); 
      this.Close(); 
     } 

예외 메시지는 :

System.Runtime.InteropServices.COMException was unhandled 
    HelpLink=wdmain11.chm#37373 
    HResult=-2146823683 
    Message=This method or property is not available because this command is not available for reading. 
    Source=Microsoft Word 
    ErrorCode=-2146823683 
    StackTrace: 
     en Microsoft.Office.Interop.Word.Range.InsertParagraphAfter() 
     en WindowsFormsApplication3.Form1.Prueba() en C:\Users\Dleekam\Google Drive\Proyectos\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs:línea 58 
     en WindowsFormsApplication3.Form1.Form1_Load(Object sender, EventArgs e) en C:\Users\Dleekam\Google Drive\Proyectos\WindowsFormsApplication3\WindowsFormsApplication3\Form1.cs:línea 25 
     en System.Windows.Forms.Form.OnLoad(EventArgs e) 
     en System.Windows.Forms.Form.OnCreateControl() 
     en System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) 
     en System.Windows.Forms.Control.CreateControl() 
     en System.Windows.Forms.Control.WmShowWindow(Message& m) 
     en System.Windows.Forms.Control.WndProc(Message& m) 
     en System.Windows.Forms.ScrollableControl.WndProc(Message& m) 
     en System.Windows.Forms.Form.WmShowWindow(Message& m) 
     en System.Windows.Forms.Form.WndProc(Message& m) 
     en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
     en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
     en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
    InnerException: 

흥미 것들

  1. 새 파일을 사용할 때 충돌이 발생하지 않습니다.
  2. 손으로 내용을 쓸 때 충돌이 없습니다.
  3. 콘텐츠 또는 콘텐츠의 일부가 복사되어 붙여 넣기 될 때.
  4. 새 문서의 내용을 삭제하고 다시 시도하면 충돌이 발생합니다.

나는 그것이 문서 원본 문서의 단어 나 단락의 서식과 관련이 있다고 생각합니다. 원본 문서의 내용을 사용할 때만 발생합니다. 하지만 아직 어떤 일이 일어나고 있는지, 어떻게 처리해야하는지, 또는이 문제를 해결하는 방법은 확실하지 않습니다. 그 예외는 그렇게 설명 적이 지 않습니다. (나는 알고 있습니다, 나는 항상 필요한 특정 정보 나 오류 메시지를받지 못할 것입니다.) 그러나 나는 이미 누군가가 똑같이, 관련되어 있거나 관련이없는 종류를 가지고 있는지보기 위해 웹을 검색했습니다. 오류가 발생했습니다.

도움이나 의견이 있으시면 언제든지 코드를 읽고 이해해 주셔서 감사합니다. 내가 VS2010 작업되었지만

답변

-1

친절한 감사 더글라스 Leekam는 내가 생각 열고 VS2013에서 솔루션의 해당 섹션을 실행하려고에 그리고 난했다. 그래서 VS2013이 15 버전의 사무실에서 요소를 인식하고 예외를 발생시키지 않는다고 가정해야합니다.

읽어 주셔서 감사합니다.