62,046
社区成员
发帖
与我相关
我的任务
分享
private void WordToHtml(string fname)
{
tfileinfoTableAdapter fileInfo = new tfileinfoTableAdapter();
try
{
// 在此处放置用户代码以初始化页面
Word.Application word = new Microsoft.Office.Interop.Word.Application();
Type wordType = word.GetType();
Word.Documents docs = word.Documents; // 打开文件
Type docsType = docs.GetType();
//object fileName = Server.MapPath("~/docs/") + fname;
var fileRecord = fileInfo.GetDataByFId(Request["fid"]).Single();
object fileName = fileRecord.fpath;
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true }); // 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = Server.MapPath("~/docs/") + fileRecord.fboard + @"/" + fileRecord.funit + @"/" + fileRecord.ftype + @"/" + fname + ".html";
//object saveFileName = Server.MapPath("~/docs/") + fname + ".html";
//保存HTML
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatHTML });
// 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
//跳转显示预案信息
//Response.Redirect("~/docs/" + fname + ".html");
Response.Redirect("~/docs/" + fileRecord.fboard + @"/" + fileRecord.funit + @"/" + fileRecord.ftype + @"/" + fname + ".html");
}
catch (Exception ex)
{
Common.ReturnScriptMsg("发生错误:" + ex.Message, "index.aspx");
}
}