This article is an example of how ASP.net implements the online preview of Word documents. Share to everyone for your reference. The implementation methods are as follows:
How to implement: Office documents to HTML, and then browse the browser online
1, first introduce the Office library in the COM component, and then introduce Word's DLL in the assembly extension
2, set the Microsoft.Office.Interop.Word embedded interop type to False, as shown in the figure
3. Main code:
Copy Code code as follows:
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>
Convert Word to HTML
</summary>
<param name= "path" > The path of the document to be converted </param>
<param name= "Savepath" > Convert to HTML save path </param>
<param name= "Wordfilename" > file names converted to 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);
}
}
}
Call:
Copy Code code as follows:
Office2htmlhelper.word2html (MapPath) ("/doc/Analysis of a website's SEO strategy (outside the chain). Doc"), MapPath ("/html/"), "analysis of a site's SEO strategy (outside the chain)");
I hope this article will help you with the ASP.net program design.