c# word转换html,C# Execl WOrd 转化为html显示在页面上

///

///

///

/// 文件路径

/// 保存html格式的路径

public static void WordHtml(string filePath, string htmlPath)

{

Word.Application wordApp;

Word.Document wordDoc;

Object Nothing = Missing.Value;

Console.WriteLine("Input path:");

Object path = Console.ReadLine();

path = filePath;

wordApp = new Word.ApplicationClass();

wordDoc = wordApp.Documents.Add(ref path, ref Nothing, ref Nothing, ref Nothing);

object format = Word.WdSaveFormat.wdFormatFilteredHTML;

Object newPath = htmlPath;

wordDoc.SaveAs(ref newPath, ref format, ref Nothing, ref Nothing, ref Nothing,

ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,

ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);

wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);

wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);

}

///

///

///

/// 文件路径

/// 保存html格式的路径

public static void ExeclHtml(string filePath, string htmlPath)

{

try

{

Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();

app.Visible = false;

app.DisplayAlerts = false;

object o = Missing.Value;

Microsoft.Office.Interop.Excel.Workbook workbook = null;

workbook = app.Workbooks.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

object fileName = htmlPath;

object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlHtml;

workbook.SaveAs(fileName, format, o, o, o, o, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, o, o, o, o);

app.Quit();

Process[] myProces = Process.GetProcessesByName("EXCEL");

foreach (Process proces in myProces)

{

proces.Kill();

}

}

catch (Exception ex)

{

System.Console.Write(ex.Message);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值