国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET實現(xiàn)word文檔在線預(yù)覽功能代碼

2024-07-10 13:25:45
字體:
供稿:網(wǎng)友
于是考慮在每個文件上傳時為其生存一份HTMl文件,這樣就能實現(xiàn)在線預(yù)覽功能。主要代碼如下

復(fù)制代碼 代碼如下:


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Word = Microsoft.Office.Interop.Word;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WordToHtml("d://yijian.doc");
}
/// <summary>
/// word轉(zhuǎn)成html
/// </summary>
/// <param></param>
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 });
//轉(zhuǎn)換格式,另存為
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();
}
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 沙洋县| 冕宁县| 云和县| 佳木斯市| 白山市| 繁峙县| 安康市| 依兰县| 无锡市| 万安县| 晴隆县| 德令哈市| 明光市| 四平市| 乌恰县| 德格县| 嘉义县| 耒阳市| 通辽市| 云龙县| 张家港市| 中方县| 班玛县| 汪清县| 宾阳县| 永年县| 明光市| 永济市| 阿巴嘎旗| 通辽市| 合水县| 惠东县| 桃源县| 潞城市| 汉阴县| 青阳县| 邵东县| 鹰潭市| 肥东县| 页游| 乐都县|