2011-11-15 3 views
2

.docx 파일을 .html로 변환하고 싶습니다. 나는 C#에서 일한다. 내 코드는 다음과 같습니다..docx를 html로 변환

Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); 
     Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document(); 
     Object oMissing = System.Reflection.Missing.Value; 
     wordDoc = word.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); 
     word.Visible = false; 
     Object filepath = @"C:\Users\John\Desktop\begin.docx"; 
     Object confirmconversion = System.Reflection.Missing.Value; 
     Object readOnly = false; 
     Object saveto = @"C:\Users\John\Desktop\result.html"; 
     Object oallowsubstitution = System.Reflection.Missing.Value; 

     wordDoc = word.Documents.Open(ref filepath, ref confirmconversion, ref readOnly, ref oMissing, 
             ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
             ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
             ref oMissing, ref oMissing, ref oMissing); 
     object fileFormat = WdSaveFormat.wdFormatHTML; 
     wordDoc.SaveAs(ref saveto, ref fileFormat, ref oMissing, ref oMissing, ref oMissing, 
         ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
         ref oMissing, ref oMissing, ref oMissing, ref oallowsubstitution, ref oMissing, 
         ref oMissing); 

문제는 헤더와 바닥 글이 포함되지 않는 것입니다. 그들은 .html 결과 파일에 없습니다. 결과에 어떻게 포함시킬 수 있습니까?

+2

수동으로 해 보았습니까? Word에서 HTML로 저장하는 것을 의미합니다. 머리글과 바닥 글이 포함되어 있습니까? – Snowbear

+0

예, 시도했지만 그렇지 않습니다. –

+0

(상업) 라이브러리는 옵션입니까? – Yahia

답변

2

Word에서 머리글과 바닥 글을 보는 이유는 기본적으로 인쇄보기에 있기 때문입니다. HTML 문서에서 머리말과 꼬리말이 존재하지 않는 "드래프트"스타일 뷰에 있습니다. HTML 문서를 인쇄 할 때 print stylesheet이라는 다른 스타일을 설정할 수 있습니다. 이 인쇄 스타일 시트는 브라우저에서 문서를 인쇄 할 때만 사용됩니다.

또 다른 옵션은 대부분의 브라우저가 PDF보기를 지원하거나 플러그인을 지원하기 때문에 PDF로 변환하여 사용자가 PDF를 볼 수있게하는 것입니다.

html 파일에 머리말과 꼬리말을 요소로 추가 한 다음 몇 가지 CSS 속임수를 사용하여 요소를 위와 아래에 표시 할 수 있습니다. 이 작업 방법을 설명하는 Here is a link.