Word.application에 의해 제공된 방법을 사용하면 Word 문서를 HTML과 같은 다른 형식으로 쉽게 변환 할 수 있습니다. 다음은 구현 된 모든 코드입니다.
시각적 C#
WordTohtml.aspx
<%@ page language = c# codebehind = wordtohtml.aspx.cs autoeventwireup = false
상속 = aspxwebcs.wordtohtml %>
<! doctype html public- // w3c // dtd html 4.0 Transitional // en>
<html>
<헤드>
<title> WordTohtml </title>
<메타 이름 = 발전기 컨텐츠 = Microsoft Visual Studio .NET 7.1>
<meta name = code_language content = c#>
<meta name = vs_defaultclientscript content = javaScript>
<meta name = vs_targetschema content = http : //schemas.microsoft.com/intellisense/ie5>
</head>
<body ms_positioning = gridlayout>
<form id = form1 method = post runat = server>
</form>
</body>
</html>
WordTohtml.aspx.cs
시스템 사용;
시스템 사용;
System.componentModel 사용;
System.Data 사용;
System.Drawing 사용;
System.Web 사용;
system.web.sessionstate 사용;
system.web.ui 사용;
system.web.ui.webcontrols 사용;
system.web.ui.htmlcontrols 사용;
사무실 사용;
네임 스페이스 ASPXWEBCS
{
/// <요약>
/// WordTohtml 요약 설명.
/// 먼저 참조 추가 : Microsoft Word 9.0 객체 라이브러리
/// </summary>
공개 클래스 WordTohtml : System.Web.ui.Page
{
private void page_load (객체 발신자, System.EventArgs e)
{
// 페이지 초기화를 위해 사용자 코드를 여기에 넣습니다.
Word.applicationClass Word = 새 Word.applicationClass ();
wordtype = word.getType ();
Word.documents Docs = Word.documents;
// 파일을 엽니 다
docstype = docs.getType ();
Object filename = d : //tmp//aaa.doc;
Word.document doc = (Word.document) doctype.invokemember (Open,
system.reflection.bindingflags.invokemethod, null, docs, new object [] {filename, true, true});
// 형식을 변환하고 AS를 저장하십시오
doctype = doc.gettype ();
객체 savefilename = d : //tmp//aaa.html;
// 다음은 Microsoft Word 9 객체 라이브러리를 작성하는 방법입니다. 10 인 경우 다음과 같이 작성 될 수 있습니다.
//doctype.invokemember(saveas, system.reflection.bindingflags.invokemethod,
null, doc, new Object [] {savefilename, word.wdsaveformat.wdformatfilternhtml});
/// 기타 형식 :
/// wdformatml
/// wdformatdocument
/// wdformatdostext
/// wdformatdostextlinebreaks
/// wdformatencodedText
/// wdformattf
/// wdformatemplate
/// wdformattext
/// wdformattextlinebreaks
/// wdformatunicodetext
doctype.invokemember (Saveas, System.reflection.bindingflags.invokemethod,
null, doc, new Object [] {savefilename, word.wdsaveformat.wdformattml});
// 단어 종료
WordType.inVokemember (Quit, System.Reflection.bindingflags.invokemethod,
NULL, WORD, NULL);
}
#영역 웹 양식 디자이너 생성 코드
보호 된 void oninit (EventArgs e)를 재정의합니다.
{
//
// CodeGen :이 호출은 ASP.NET 웹 양식 디자이너에게 필요합니다.
//
InitializeComponent ();
Base.oninit (e);
}
/// <요약>
/// Designer는 필요한 방법을 지원합니다 - 코드 편집기를 사용하여 수정하지 마십시오.
///이 방법의 내용.
/// </summary>
private void initializecomponent ()
{
this.load += new System.eventhandler (this.page_load);
}
#endregion
}
}