Mvc+easyui-based Web development Framework Experience Summary (8)--Implement a preview of Office documents

Source: Internet
Author: User

In many articles, there have been some introduction to the Office Document Preview view operations, some by turning to PDF to view, some by converting it to flash to view, but the process is a curve to the salvation, really simple and convenient to implement the Office document preview or relatively small, The Office documents here include word, Excel, and PPT documents. This article describes two ways of using Microsoft's platform for online viewing of Office documents through online previews, one for viewing Office documents after generating HTML files. Then compare their pros and cons and summarize them.

1. Online viewing of Office documents using Microsoft's platform

All along, we want to find a suitable control or solution for Office documents, so that when the customer is using the system, they can view the preview of some documents directly without installing Office or downloading to a local view.

An accidental opportunity to search the Web for Microsoft to provide an online service, can be implemented to convert Office documents to online content to view, you can see through the following link address: http://blogs.office.com/2013/04/10/ office-web-viewer-view-office-documents-in-a-browser/.

The link address format for viewing Office documents directly using the browser is as follows:

Http://view.officeapps.live.com/op/view.aspx?src=http%3a%2f%2fvideo.ch9.ms%2fbuild%2f2011%2fslides%2fTOOL-532T_Sutter.pptx

This link is divided into two parts, one for http://view.officeapps.live.com/op/view.aspx?src=, the other for the specific document address, and a link address for processing with UrlEncode.

Very cool effect, the only requirement for using this service is that your site is deployed on the Internet so that the service can call your document address and then display it.

This is a preview of office services using Microsoft, of course you can deploy your own Office preview service, that is, you need to install the Office Web Apps Service (System Requirements for Windows Server 2012)

In general, Office Web Apps is used in conjunction with other apps, as shown (it seems to be quite complex, and these things seem to be installed on separate machines as well):

650) this.width=650; "title=" clip_image035 "src=" http://images.cnitblog.com/blog/112695/201308/05150210- Af4ed42ccc8b4fe492bfab1570b8a99f.png "alt=" clip_image035 "width=" 604 "height=" 555 "border=" 0 "style=" border:0px; "/ >

Fortunately, Microsoft has provided us with an online Office Document preview service, as if Google Doc Viewer is available, but it is not available. This allows us to make an online preview of Office documents with a public interface address.

As an example of a commonly used Excel document, it can provide a perfect online preview effect.

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/280940374468761.png "style=" border:0px; "/>

We also noted that there is a row of menus that can expand the operation of related functions, especially the downloading and printing of documents is very attractive.

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/280941230874183.png "style=" border:0px; "/>

So that we can integrate on our Document Preview Operations page, here's an example of my integration with the Mvc4+easyui Web development Framework, which I'll look at in my Office document.

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/280950347742174.png "style=" border:0px; "/>

It feels good.

Word documents can also be previewed smoothly, but there are no features to print and download, but the preview is good.

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/281001549774568.png "style=" border:0px; "/>

2. View Office documents after generating HTML files

That said, using the online Office preview service to view Office documents, if our management system is running on the LAN, then we just can't use it, so if we need to use this online preview of Office Document Services, how should we do?

While building your own Office Web Apps service can solve this problem, in general, it is too cumbersome and expensive to build such a platform environment, is there a better way to implement Office document viewing?

Yes, let me show you how to use the Aspose component to generate HTML for an Office document and then see how it is done.

For different Office documents, Aspose provides different components, such as Aspose.word, Aspose.cells, Aspose.slides, and so on, to handle several documents such as Word/excel/ppt.

We know that the Aspose component is very powerful in dealing with Office documents, but it is also a paid software, so we need to be able to buy support, but here we talk purely about its functional effects.

For different file types, we invoke different components for the HTML conversion, and the core code is shown below.

if  (ext ==  "Doc"  | |  ext ==  "Docx") {aspose.words.document doc = new aspose.words.document ( templatefile);d OC. Save (generatefilepath, aspose.words.saveformat.html);} else if  (ext ==  "xls"  | |  ext ==  "xlsx") {Workbook workbook = new workbook (templatefile); Workbook. Save (generatefilepath, saveformat.html);} else if  (ext ==  "ppt"  | |  ext ==  "Pptx") {Templatefile = templatefile.replace ("/",  "\"); Presentationex pres = new presentationex (templatefile);p Res. Save (generatefilepath, aspose.slides.export.saveformat.html);} 

In this way, when we first use, determine whether there is a corresponding HTML file in the directory, if not, use the above code generation can be, when viewing, return the corresponding path to the client to view the file on it.

Here are the effects of several documents for reference.

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/281031190717827.png "style=" border:0px; "/>

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/281031273376434.png "style=" border:0px; "/>

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/281031354157799.png "style=" border:0px; "/>

3. Preview the integration of both online and local generated files

When we do the project, often do not know the specific application is deployed in the public Network (Internet) environment, or in the LAN environment, so we require a lot of features need to have a certain degree of flexibility, if you can use the public network, using the public network Microsoft Office Preview function, The resulting effect is better than using the Aspose component, and sometimes the format of the document generated by the Aspose component may be somewhat different (though overall good).

Therefore, if you can configure the two as needed, switching, it should be a more ideal solution.

Here are some of the things I've done to integrate the previews of both of them, switching from one variable to the next, and, of course, the variables can be written to the config file, so that you can change the code in a different way later.

bool officeinternetview = false;//whether to use Internet online preview string hostname =  Httputility.urlpathencode ("http://www.iqidi.com/");//Can be configured, if necessary if  (ext ==  "xls"  | |  ext ==  "xlsx"  | |  ext ==  "Doc"  | |  ext ==  "Docx"  | |  ext ==  "ppt"  | |  ext ==  "pptx") {if  (Officeinternetview) {//Return a Microsoft online Browse office address, need to add an Internet domain name or public IP address Viewurl  = string. Format ("Http://view.officeapps.live.com/op/view.aspx?src={0}{1}",  hostname, filepath);} else{#region   Dynamic First generate file//check if the local Office file exists, if it does not exist, and then return the path for viewing string webpath = string. Format ("/generatefiles/office/{0}.htm",  info.id); String generatefilepath = server.mappath ( Webpath);if  (! Fileutil.fileisexist (Generatefilepath)) {string templatefile = bllfactory<fileupload>. Instance.getfilepath (info); Templatefile = path.combine (System.AppDomain.CurrentDomaiN.basedirectory, templatefile.replace ("\ \",  "/"));if  (ext ==  "Doc"  | |  ext ==  "Docx") {aspose.words.document doc = new aspose.words.document ( templatefile);d OC. Save (generatefilepath, aspose.words.saveformat.html);} else if  (ext ==  "xls"  | |  ext ==  "xlsx") {Workbook workbook = new workbook (templatefile); Workbook. Save (generatefilepath, saveformat.html);} else if  (ext ==  "ppt"  | |  ext ==  "Pptx") {Templatefile = templatefile.replace ("/",  "\"); Presentationex pres = new presentationex (templatefile);p Res. Save (generatefilepath, aspose.slides.export.saveformat.html);}} #endregionviewUrl  = webpath;}} Else{viewurl = filepath;}

Finally, I implemented the display of all the documents in the Attachment Management module, which can be previewed for Office documents and picture documents, as well as other documents for downloading.

650) this.width=650; "src=" Http://images.cnitblog.com/i/8867/201407/281043048838330.png "style=" border:0px; "/>

The following is a closer look at the operational capabilities of the attachment Management module on the web framework.


This article is from the "Wu Huacong blog" blog, make sure to keep this source http://wuhuacong.blog.51cto.com/1779896/1828948

Mvc+easyui-based Web development Framework Experience Summary (8)--Implement a preview of Office documents

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.