實現方式:office文檔轉html,再在瀏覽器里面在線瀏覽
1、首先引入com組件中office庫,然后在程序集擴展中引入word的dll
2、將Microsoft.Office.Interop.Word的嵌入互操作類型設置為 false,如圖
3、主要代碼
C# 代碼
復制
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轉成Html
/// </summary>
/// <param name="path">要轉換的文檔的路徑</param>
/// <param name="savePath">轉換成html的保存路徑</param>
/// <param name="wordFileName">轉換成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);
}
}
} 
調用
Office2HtmlHelper.Word2Html(MapPath("/Doc/分析某網站的SEO策略(外鏈篇).doc"), MapPath("/Html/"), "分析某網站的SEO策略(外鏈篇)");