Word.Applicationで提供されるメソッドを使用して、WordドキュメントをHTMLなどの他の形式に簡単に変換できます。以下はすべて実装されているコードです。
ビジュアルC#
wordtohtml.aspx
<%@ページ言語= c#codebehind = wordtohtml.aspx.cs autoeventwireup = false
継承= aspxwebcs.wordtohtml%>
<!doctype html public - // w3c // dtd html 4.0 transitional // en>
<html>
<head>
<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.Collectionsを使用します。
System.comPonentModelを使用しています。
System.Dataを使用しています。
System.drawingを使用しています。
system.webを使用しています。
System.Web.SessionStateを使用しています。
system.web.uiを使用しています。
System.Web.ui.WebControlsを使用します。
System.web.ui.htmlControlsを使用します。
オフィスの使用;
名前空間ASPXWEBCS
{
/// <summary>
/// wordtohtml要約の説明。
///最初に、参照を追加:MicrosoftWord 9.0オブジェクトライブラリ
/// </summary>
パブリッククラスのwordtohtml:system.web.ui.page
{
private void page_load(object sender、system.eventargs e)
{
//ページを初期化するためにユーザーコードをここに配置します
word.applicationclass word = new Word.ApplicationClass();
type 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.wdformatfilteredhtml});
///その他の形式:
/// wdformatml
/// wdformatdocument
/// wdformatdostext
/// WDFORMATDOSTEXTLINEBREAKS
/// wdformateCodedText
/// wdformattf
/// wdformattemplate
/// wdformattext
/// wdformattextlinebreaks
/// wdformatunicodetext
doctype.invokemember(saveas、system.reflection.bindingflags.invokemethod、
null、doc、new object [] {savefilename、word.wdsaveformat.wdformattml});
// wordを終了します
wordtype.invokemember(quit、system.reflection.bindingflags.invokemethod、
null、word、null);
}
#region Webフォームデザイナー生成コード
オーバーライド保護されたvoid oninit(eventargs e)
{
//
// CodeGen:この呼び出しは、ASP.NET Webフォームデザイナーに必要です。
//
initializeComponent();
base.oninit(e);
}
/// <summary>
///デザイナーが必要な方法をサポート - コードエディターを使用して変更しないでください
///このメソッドの内容。
/// </summary>
private void initializeComponent()
{
this.load += new System.EventHandler(this.page_load);
}
#endregion
}
}