首页 新闻 赞助 找找看

.net 获取word文档内容前台输出不生成新的HTML页 只要HTML代码在aspx页显示

0
[已关闭问题] 关闭于 2017-12-16 09:00

public partial class Default2 : System.Web.UI.Page
{
public string cddd = "";
protected void Page_Load(object sender, EventArgs e)
{

string strFilePath = "";
strFilePath = Server.MapPath("123.doc");
cddd = WordToHtml(strFilePath);
}
private string WordToHtml(object wordFileName)
{
//在此处放置用户代码以初始化页面
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
//打开文件
Type docsType = docs.GetType();
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true });
//转换格式,另存为
Type docType = doc.GetType();
string wordSaveFileName = wordFileName.ToString();
string strSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.Length - 3) + "html";
object saveFileName = (object)strSaveFileName;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML });
docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
//退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
return saveFileName.ToString();
}
}

慌什么的主页 慌什么 | 菜鸟二级 | 园豆:212
提问于:2017-12-03 11:09
< >
分享
所有回答(1)
0

将WORD读取结果返回字符串用AJAX方式输出到HTML页面?

风不平 | 园豆:118 (初学一级) | 2017-12-03 11:14

现在的代码生成一个新的HTML页面 我想直接把word文档的内容转换为HTML代码 直接在aspx页显示 不要新的HTML页面

支持(0) 反对(0) 慌什么 | 园豆:212 (菜鸟二级) | 2017-12-03 11:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册