Asp.net: How to preview Word documents online, asp. netword
Implementation Method: Convert the office document to html and then browse it online in the browser
1. first introduce the office library in the com component, and then introduce the dll of word in the Assembly extension.
2. Set the embedded interoperability type of Microsoft. Office. Interop. Word to false,
3. Main Code
C # code Replication
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"> document to be converted </param> /// <param name = "savePath"> convert to html storage path </param> /// <param name = "wordFileName"> html file name </param> public static void Word2Html (string path, string savePath, string wordFileName) {Word. applicationClass word = new Word. applicationClass (); Type wordType = word. getType (); Word. required ents 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
Office2HtmlHelper. Word2Html (MapPath ("/Doc/analysis of a website's seostrategy ( .doc"), MapPath ("/Html/"), "Analysis of a website's SEO strategy (external links )");
Aspnet is similar to Baidu Library Online Preview word implementation
What is the purpose of Online Preview? If it is to prevent users from downloading, it is necessary to make it the same as Baidu Library. If you look at the web page, you can simply open it on the web page.
The Source Code cannot be provided to you, involving unit information. It can only tell you how to implement it: Use the virtual printing technology to print word into an image, convert it to swf, or convert word to pdf, and then convert the pdf to swf with pdfswf.exe. After converting to swf, use flexpager to browse. There are many materials on the Internet. You need to pay attention to this problem. The Document Style conversion is prone to major problems. We recommend that you use word to print it as an image, the disadvantage is that the file size is large but simple.
How can I preview doc files online on an asp Website?
I was doing this. when viewing the. net document, a tool named flashpaper is used to convert the Word document into a swf file, and then embed it into the webpage as flash for viewing.
In addition, asp.net has components that support office. asp has never seen this plug-in.