Original: How to implement online preview of Word document in ASP.
Implementation: Office documents to HTML, and then in the browser online browsing
1. First introduce the Office library in the COM component and then introduce the word DLL in the assembly extension
2. Set the embedded interop type of Microsoft.Office.Interop.Word to False,
3. Main code
C # codeCopy
UsingSystem;UsingSystem.Collections.Generic;UsingSystem.Linq;Usingsystem.web;UsingMicrosoft.Office.Core;UsingWord=Microsoft.Office.Interop.Word;NamespaceWolfy.officepreview{Public ClassOffice2htmlhelper{/// <summary> ///Word turns into HTML/// </summary> /// <param name= "Path" >The path of the document to convert</param> /// <param name= "Savepath" >Convert to HTML save path</param> /// <param name= "Wordfilename" >File name converted to HTML</param> Public Static voidWord2html (StringPathStringSavepath,StringWordfilename){Word.applicationclass Word= NewWord.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,NewObject[]{ (Object) path,True,True}); Type DocType=Doc. GetType ();StringStrsavefilename=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 ); } } /span>
Call
Office2htmlhelper.word2html (MapPath ("/doc/analysis of a website's SEO strategy (external links). Doc"), MapPath ("/html/"), " Analysis of a website's SEO strategy (external link)");
How to implement online preview of Word documents in ASP