asp.net practical tips for implementing online preview of Word documents

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.