具体代码:using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using WordApp = Microsoft.Office.Interop.Word;namespace bjj.ProjectTest { /// <summary> /// DocToHtml 的摘要说明。 /// </summary> public class DocToHtml : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { tranhtml(); // 在此处放置用户代码以初始化页面 } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); }
你就这样搜一下就有了
若找不到,我可以找一个给你
最近做了一个转成mht的
using WordApp = Microsoft.Office.Interop.Word;
private void tranhtml()
{
object missingValue = Type.Missing;
WordApp._Application wapp = new WordApp.Application();
object openfile = "E:\\documents\\first_love.doc";
WordApp._Document doc = wapp.Documents.Open(ref openfile, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);
//doc.Path = "E:\\documents\\first_love.doc";
object fn = "c:\\1.htm";
object st = WordApp.WdSaveFormat.wdFormatHTML;
doc.SaveAs(ref fn, ref st, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);
doc.Close(ref missingValue, ref missingValue, ref missingValue);
wapp.Quit(ref missingValue, ref missingValue, ref missingValue);
}
(我用的是Word 2003)
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using WordApp = Microsoft.Office.Interop.Word;namespace bjj.ProjectTest
{
/// <summary>
/// DocToHtml 的摘要说明。
/// </summary>
public class DocToHtml : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
tranhtml();
// 在此处放置用户代码以初始化页面
} #region Web 窗体设计器生成的代码
override protected 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
private void tranhtml()
{
object missingValue = Type.Missing;
WordApp._Application wapp = new WordApp.ApplicationClass();;
object openfile = "E:\\mytest.doc";
WordApp._Document doc = wapp.Documents.Open(ref openfile, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);
//doc.Path = "E:\\documents\\first_love.doc";
object fn = "c:\\1.htm";
object st = WordApp.WdSaveFormat.wdFormatHTML;
doc.SaveAs(ref fn, ref st, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue, ref missingValue);
doc.Close(ref missingValue, ref missingValue, ref missingValue);
wapp.Quit(ref missingValue, ref missingValue, ref missingValue);
} //打开Word文档再存为html
}}
不同版本的OFFICE调用的函数是有些区别的.