7,765
社区成员
发帖
与我相关
我的任务
分享
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<iframe src="../../temp/aa.doc" marginwidth="0" marginheight="0" frameborder="0"
width="100%" height="100%"></iframe>
</div>
</div>
</form>
</body>
</html>
Response.AppendHeader("Content-Disposition", "inline;filename=" & fileName)
Response.ContentType = "application/ms-excel"
Response.WriteFile(strPath)
Response.Flush()
//filePath:word源文件地址,savePath:保存的文件夹地址
public static void Doc2html(string filePath, string savePath)
{
//转化后的mhtml保存地址
object fileSaveName = savePath + filePath.Substring(filePath.LastIndexOf("\\"), filePath.LastIndexOf(".") - filePath.LastIndexOf("\\")) + ".mhtml";
if (File.Exists(fileSaveName.ToString()))
{
return;
}
//实例化COM
Microsoft.Office.Interop.Word.ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object fileobj = filePath;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = null;
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
try
{
doc = wordApp.Documents.Open(ref fileobj, ref nullobj, ref vk_read_only,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref vk_read_only, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
//word转换格式
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatWebArchive;
//将word转换为mhtml
doc.SaveAs(ref fileSaveName, ref format, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
}
catch (Exception exp)
{
MessageBox.Show(exp.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
if (doc != null)
{
//关闭文件
doc.Close(ref vk_false, ref nullobj, ref nullobj);
}
if (wordApp != null)
{
wordApp.NormalTemplate.Saved = true;
//关闭COM
wordApp.Quit(ref vk_false, ref nullobj, ref nullobj);
}
}
}