การใช้วิธีการที่จัดทำโดย Word.Application คุณสามารถแปลงเอกสาร Word เป็นรูปแบบอื่น ๆ เช่น HTML ได้อย่างง่ายดาย ต่อไปนี้เป็นรหัสทั้งหมดที่ใช้:
Visual C#
wordtohtml.aspx
<%@ page language = c# codebehind = wordtohtml.aspx.cs autoEventWireUp = false
สืบทอด = aspxwebcs.wordtohtml %>
<! doctype html สาธารณะ -// w3c // dtd html 4.0 transitional // en>
<html>
<head>
<title> wordtohtml </title>
<meta name = generator content = Microsoft Visual Studio .net 7.1>
<meta name = code_language content = c#>
<meta name = vs_defaultClientScriptive = JavaScript>
<meta name = vs_targetschema content = http: //schemas.microsoft.com/intellisense/ie5>
</head>
<body ms_positioning = gridlayout>
<form id = method form1 = post runat = เซิร์ฟเวอร์>
</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
/// ก่อนอื่นเพิ่มการอ้างอิง: Microsoft Word 9.0 Object Library
/// </summary>
คลาสสาธารณะ WordtoHtml: System.web.ui.Page
-
โมฆะส่วนตัว page_load (ผู้ส่งวัตถุ, system.eventargs e)
-
// ใส่รหัสผู้ใช้ที่นี่เพื่อเริ่มต้นหน้าเว็บ
word.applicationclass word = new word.applicationclass ();
พิมพ์ wordType = word.getType ();
word.documents docs = word.documents;
// เปิดไฟล์
พิมพ์ docStype = docs.getType ();
FileName Object = D: //tmp//aaa.doc;
word.document doc = (word.document) doctype.invokemember (เปิด,
System.reflection.bindingflags.invokemethod, null, เอกสาร, วัตถุใหม่ [] {ชื่อไฟล์, จริง, จริง, จริง});
// แปลงรูปแบบบันทึกเป็น
พิมพ์ doctype = doc.getType ();
Object saveFilename = d: //tmp//aaa.html;
// ต่อไปนี้เป็นวิธีการเขียนไลบรารี Object Microsoft Word 9 ถ้าเป็น 10 อาจเขียนเป็น:
//doctype.invokemember(Saveas, System.reflection.bindingflags.invokemethod,
null, doc, วัตถุใหม่ [] {savefilename, word.wdsaveformat.wdformatfilteredhtml});
/// รูปแบบอื่น ๆ :
/// WDFORMATML
/// wdformatDocument
/// wdformatDostext
/// wdformatDostExtLineBreaks
/// wdformatenCodedText
/// WDFORMATTF
/// wdformattemplate
/// wdformattext
/// WDFormatTextLineBreaks
/// wdformatunicodetext
doctype.invokemember (saveas, system.reflection.bindingflags.invokemethod,
null, doc, วัตถุใหม่ [] {savefilename, word.wdsaveformat.wdformattml});
// ออกจากคำ
WordType.invokemember (ออก, system.reflection.bindingflags.invokemethod,
null, word, null);
-
#REGION Web Form Designer สร้างรหัส
แทนที่โมฆะป้องกัน oninit (EventArgs E)
-
-
// codegen: การโทรนี้เป็นสิ่งจำเป็นสำหรับนักออกแบบเว็บฟอร์ม ASP.NET
-
เริ่มต้นคอมเพล็กซ์ ();
base.oninit (e);
-
/// <summary>
/// นักออกแบบรองรับวิธีการที่จำเป็น - อย่าใช้โปรแกรมแก้ไขรหัสเพื่อแก้ไข
/// เนื้อหาของวิธีนี้
/// </summary>
โมฆะส่วนตัวเริ่มต้นคอมเม้นต์ ()
-
this.load += new System.eventHandler (this.page_load);
-
#endregion
-
-