[ASP] Common Word,excel,ppt,pdf Online preview scheme (GO)

Source: Internet
Author: User

Introduction

Before the project needed, looked for the Office document online preview solution, by the way record, convenient later query.

Programme I

Open the link to the Office document on the page directly in the browser. The following window will pop up:

Pros: Mainstream browsers are supported.

Disadvantage: The Office Document link opens in the browser, will be like the hint, need the user to choose to open or save the function, if the customer computer installed Thunderbolt download software, will start thunder download, user experience is not good.

Programme II

Office document to HTML, first introduce the Office library in the COM component, and then introduce the word,excel,ppt DLL in the assembly extension.

Then the F6 is generated and the following error is reported:

Workaround:

Office Document Conversion HTML helper classes:

Office2htmlhelperoffice2html.aspx
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 8 namespaceWolfy.officepreview9 {Ten      Public Partial classOffice2Html:System.Web.UI.Page One     { A         protected voidPage_Load (Objectsender, EventArgs e) -         { -  the         } -         protected voidBtnword_click (Objectsender, EventArgs e) -         { -Button btn = Sender asButton; +             Switch(btn.commandargument) -             { +                  Case "docx": AOffice2htmlhelper.word2html (MapPath ("/doc/Analysis of a website's SEO strategy (external link). Doc"), MapPath ("/html/"),"analyze the SEO strategy of a website (external link)"); at                      Break; -                  Case "xlsx": -Office2htmlhelper.excel2html (MapPath ("/excel/1994-2013 The minimum wage standard of Beijing in the past years. xlsx"), MapPath ("/html/"),"1994-2013 minimum wage standard in Beijing over the years"); -                      Break; -                  Case "ppt": -Office2htmlhelper.ppt2html (MapPath ("/PPT/23 Design pattern detailed. PPT"), MapPath ("/html/"),"23 Design Patterns in a detailed way"); in                      Break; -                 default: to                      Break; +             } -         } the     } *}

Test results:

Here to test the Office documents containing pictures, browse the normal:

Requirements: The machine needs to install Office, and Office environment is pure, so-called pure can not have more than one version, LZ once installed on the computer WPS, is suffering the pain has always reported the following error:

Reported this mistake, can only cry, online about 00046 of the solution have tried, no. Then had to reinstall Office, and then laughed. It is best to install the full version of Office, because the original installed is not the full version, do not know if there is no reason for this, there is no test, recommend the full version.

Programme III

Office documents go to Pdf,pdf to SWF and use Flexpaper+swftools for online browsing.

in the action office2007 installation is required. SaveAsPDFandXPS.exe , after successful installation,:

only the installed SaveAsPDFandXPS.exe , program Operation Office document, only Office Save document as PDF file. OFFICE2010 does not need to be installed, built-in with this feature.

Core code:

Office2pdfhelper office2pdfoffice2pdf.aspx

Test results:

The process of office to PDF files in this scenario requires the same requirements as scenario two.

Once the PDF conversion is complete, you can convert the PDF to SWF and use Flexpaper+swftools for online browsing, and refer to one of my previous articles:

flexpaper+swftool+ Action class = online preview pdf

Programme IV

Office documents are converted directly to SWF, using Flexpaper+swftool for earlier browsing.

Office translates directly to SWF, which is implemented using Flashpaper:

Flashpaper is a virtual printer that converts a word file directly into a SWF format File (. doc.xls. txt. pdf files can be generated in SWF format as normal ) .

Only the core code is posted here:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Diagnostics;4 usingSystem.Linq;5 usingsystem.web;6 usingSystem.Web.UI;7 usingSystem.Web.UI.WebControls;8 9 namespaceWolfy.officepreviewTen { One      Public Partial classOffice2Swf:System.Web.UI.Page A     { -         protected voidPage_Load (Objectsender, EventArgs e) -         { the  -         } -         protected voidBtnword_click (Objectsender, EventArgs e) -         { +Button btn = Sender asButton; -             Switch(btn.commandargument) +             { A                  Case "docx": atConvertoffice2swf (MapPath ("/doc/Analysis of a website's SEO strategy (external link). Doc"), MapPath ("/swf/Analysis of a website's SEO strategy (external link). SWF")); -                      Break; -                  Case "xlsx": -Office2pdfhelper.xlsconverttopdf (MapPath ("/excel/1994-2013 The minimum wage standard of Beijing in the past years. xlsx"), MapPath ("/swf/1994-2013 The minimum wage standard of Beijing in the past years. SWF")); -                      Break; -                  Case "ppt": inOffice2pdfhelper.pptconverttopdf (MapPath ("/PPT/23 Design pattern detailed. PPT"), MapPath ("/SWF/23 Design pattern detailed. SWF")); -                      Break; to                 default: +                      Break; -             } the         } *         /// <summary> $         ///Office to SwFPanax Notoginseng         /// </summary> -         /// <param name= "OfficePath" >the Office document path to convert</param> the         /// <param name= "Swfpath" >path of the converted SwF</param> +         Private voidCONVERTOFFICE2SWF (stringOfficePath,stringSwfpath) A         { theProcess Process =NewProcess ();//Create a Process object +ProcessStartInfo StartInfo =NewProcessStartInfo (); -             stringPaperroot =@"C:\Program files\macromedia\flashpaper 2\flashprinter.exe";//This is Flashprinter's path. $             stringDocfile =OfficePath; $             stringSwffile =Swfpath; -Startinfo.filename =Paperroot; -Startinfo.arguments = Docfile +"- o"+Swffile; theStartinfo.useshellexecute =false;//booting without using the system shell -Startinfo.redirectstandardinput =false;//do not redirect inputWuyiStartinfo.redirectstandardoutput =false;//REDIRECT output theStartinfo.createnowindow =true;//do not create a window -Process. StartInfo =StartInfo; Wu process.   Start ();  -             if(Process! =NULL) About process. Close (); $             -         } -     } -}

In view of the test, when flashpaper the Office document to SWF, when using Flexpaper browsing, the content of the conversion appears empty, guessing: flexpaper can open the SWF file is incompatible with the Flashpaper to go SWF file. Finally, use Flashpaper to convert Office documents to PDF, then go to Scenario three, PDF to SWF steps. Another local test, no problem. The project is deployed on IIS, cannot be browsed, there is a deadlock situation, debugging found that the file is too large, in the case of Office has not fully converted to PDF, the Swftool tool to find the PDF file, an error occurred.

IIS, unable to browse, query the online solution, and permissions for this piece about, follow the steps set up, did not, a little regret.

Programme five

Using Dot Poly Company's Weboffice control, the test found poor compatibility, abandonment. Interested can be studied.

Programme VI

After office to PDF, the direct browser opens, which allows you to open a pdf file directly, given that the current mainstream browser integrates adobe Reader functionality . You can open the PDF file link directly.

Prerequisites: Install Adobe Reader-like software locally.

Summary

In view of the project situation to choose a suitable scheme, which has a plan is only the curve to salvation, but also to meet the requirements. If you feel that you have some help, may wish to recommend, let more people can see, thank you can see the article finally.

Reference article:

Http://www.cnblogs.com/expectszc/archive/2012/04/04/2432149.html

Http://www.cnblogs.com/lexlin/articles/2478027.html

Http://www.cnblogs.com/gossip/p/3473024.html

Http://www.cnblogs.com/expectszc/archive/2012/04/04/2432149.html

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.