亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

asp.net實(shí)現(xiàn)word文檔在線預(yù)覽功能的方法

 更新時(shí)間:2014年11月05日 16:55:32   投稿:shichen2014  
這篇文章主要介紹了asp.net實(shí)現(xiàn)word文檔在線預(yù)覽功能的方法,可實(shí)現(xiàn)office文檔轉(zhuǎn)html,再在瀏覽器里面在線瀏覽,是非常實(shí)用的技巧,需要的朋友可以參考下

本文實(shí)例講述了asp.net實(shí)現(xiàn)word文檔在線預(yù)覽功能的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

實(shí)現(xiàn)方式:office文檔轉(zhuǎn)html,再在瀏覽器里面在線瀏覽

1、首先引入com組件中office庫,然后在程序集擴(kuò)展中引入word的dll

2、將Microsoft.Office.Interop.Word的嵌入互操作類型設(shè)置為 false,如圖

3、主要代碼:

復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Office.Core;
using Word = Microsoft.Office.Interop.Word;
namespace Wolfy.OfficePreview
{
    public class Office2HtmlHelper
    {
        /// <summary>
        /// Word轉(zhuǎn)成Html
        /// </summary>
        /// <param name="path">要轉(zhuǎn)換的文檔的路徑</param>
        /// <param name="savePath">轉(zhuǎn)換成html的保存路徑</param>
        /// <param name="wordFileName">轉(zhuǎn)換成html的文件名字</param>
        public static void Word2Html(string path, string savePath, string 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[] { (object)path, true, true });
            Type docType = doc.GetType();
            string strSaveFileName = savePath + wordFileName + ".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);
            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
        }
    }
}

調(diào)用:
復(fù)制代碼 代碼如下:
Office2HtmlHelper.Word2Html(MapPath("/Doc/分析某網(wǎng)站的SEO策略(外鏈篇).doc"), MapPath("/Html/"), "分析某網(wǎng)站的SEO策略(外鏈篇)");

希望本文所述對(duì)大家的asp.net程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論