2012-02-02 3 views
-1

기본적으로 WWW에서 .doc 파일을 표시하고 싶습니다. 아래 코드로 데이터를 가져 오려고했습니다. .doc에서 데이터를 가져올 수는 있지만 출력 형식이 아닙니다. .DOC.doc의 잘못된 표시 형식

B 내부

데이터

C

출력 결과

A B C

내 예상 결과

B

C이다

보호 무효 Button2_Click (객체 송신자는 EventArgs E) {

 Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); 

     // File Path 

     string strFilePath = @"C:\Users\Roy\Desktop\fypdoc.doc"; 

     // Create obj filename to pass it as paremeter in open 
     object objFile = strFilePath; object objNull = System.Reflection.Missing.Value; 

     object objReadOnly = true;//Open Document 
     Microsoft.Office.Interop.Word.Document Doc = wordApp.Documents.Open(ref objFile, ref objNull, ref objReadOnly, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull); 

     // To read each line consider each line as paragraph Docuemnt 

     int i = 1; 

     foreach (Microsoft.Office.Interop.Word.Paragraph objParagraph in Doc.Paragraphs) 
     { 

      try 
      { 
       p1.InnerHtml += Doc.Paragraphs[i].Range.Text.Replace(Environment.NewLine,"</br>"); 

      } 
      catch (Exception ex) { throw ex; } i++; 

     } // close document and Quit Word ApplicationDoc.Close(ref objNull, ref objNull, ref objNull); 

     wordApp.Quit(ref objNull, ref objNull, ref objNull); 

    } 

답변

3

대신 줄 바꿈을 사용하는 단락의 의미 값을 유지하려고 :

p1.InnerHtml += "<p>" + Doc.Paragraphs[i].Range.Text + "</p>"; 
+0

thanks! it work =) –

0

<br /></br>를 교체하십시오.

+0

잘 작동하지 않았 음 = ( –

0

내가 여기 문제가 당신이 3 단락에서 읽기, 아직 때 사이에 추가 행을 추가하지 않을 것입니다 생각을 html로 전송.

0

각 단락을 반복하는 것처럼 보입니다. 각 단락이 linebreaks로 구분 된 텍스트 블록이 될 것으로 예상하는 경우에는 줄 바꿈 자체가 포함되지 않습니다.

텍스트를 연결 한 후 br를 추가하거나 단락 태그를 사용하십시오.