C# 如何word转html
展开全部
public void WordToHtmlFile(string WordFilePath)
{
try
{
Word.Application wApp = new Word.Application(); //创建Application对象
object docPath = WordFilePath; //指定原文件和目标文件
string htmlPath = WordFilePath.Substring(0, WordFilePath.Length - 3) + "html";//设置保存的HML网页路径
object Target = htmlPath;
object Unknown = Type.Missing; //缺省参数
object readOnly = true; //只读方式打开
Word.Document document = wApp.Documents.Open(ref docPath, ref Unknown,//打开doc文件
ref readOnly, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
object format = Word.WdSaveFormat.wdFormatHTML; //指定格式
document.SaveAs(ref Target, ref format, //转换格式
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
((Word._Document)document).Close(ref Unknown, ref Unknown, ref Unknown); //关闭文档和Word程序
((Word._Application)wApp).Quit(ref Unknown, ref Unknown, ref Unknown); //关闭对象
}
catch (Exception e)
{
Response.Write("<script>alert('"+e.Message+"');</script>");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询