word关闭html显示,InvokeMember打开Word文档另存为Html页如何先关闭Html再退出Word ?_html/css_WEB-ITnose...

public partial class CountyTown : System.Web.UI.Page

{

public string countyName = string.Empty; //乡镇名称

public string documentFullName = string.Empty; //预案全称(包括后缀名)

public string documentName = string.Empty; //预案名称

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

try

{

//根据传递过来的乡镇名称获取到文件名称

countyName = Request["space"];

documentFullName = "江谭乡防台风和山洪灾害防治预案.docx";

documentName = documentFullName.Substring(0,documentFullName.LastIndexOf('.'));

}

catch (Exception)

{

documentFullName = "";

}

}

// 在此处放置用户代码以初始化页面

Application word = new Application();

Type wordType = word.GetType();

Documents docs = word.Documents; // 打开文件

Type docsType = docs.GetType();

object fileName = Server.MapPath(@"~\UpLoad\") + documentFullName;

Document doc = (Document)docsType.InvokeMember("Open",BindingFlags.InvokeMethod,null, docs,new Object[]{fileName, true, true }); // 转换格式,另存为

Type docType = doc.GetType();

object saveFileName = Server.MapPath(@"\UpLoad\") +documentName + ".html";

//string j="text/javascript";

ClientScript.RegisterClientScriptBlock(GetType(), "", "");

//保存HTML(报错:Word 无法保存此文件,因为它已在别处打开。)

docType.InvokeMember("SaveAs",BindingFlags.InvokeMethod, null, doc, new object[] {

saveFileName, WdSaveFormat.wdFormatHTML });

// 退出 Word

wordType.InvokeMember("Quit",BindingFlags.InvokeMethod, null, word, null);

Response.Redirect("~/Upload/" + documentName + ".html");

}

回复讨论(解决方案)

你本地测试不要打开word文档,将打开的word文档关闭掉。

没有打开word文档?0a20126a865379513d6cb6b270bc8eb7.png

声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值