In the blog Park many articles, there have been some introduction to the Office Document Preview view operations, some through to PDF to view, some by converting it to flash to view, but the process is the curve of 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):
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.
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.
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.
It feels good.
Word documents can also be previewed smoothly, but there are no features to print and download, but the preview is good.
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=NewAspose.Words.Document (templatefile); Doc. Save (Generatefilepath, Aspose.Words.SaveFormat.Html); } Else if(ext = ="xls"|| ext = ="xlsx") {Workbook Workbook=NewWorkbook (templatefile); Workbook. Save (Generatefilepath, saveformat.html); } Else if(ext = ="ppt"|| ext = ="pptx") {TemplateFile= Templatefile.replace ("/","\\"); Presentationex pres=NewPresentationex (templatefile); Pres. 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.
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.
BOOLOfficeinternetview =false;//whether to use Internet preview online stringHostName = 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 addressViewurl =string. Format ("Http://view.officeapps.live.com/op/view.aspx?src={0}{1}", HostName, FilePath); } Else { #regionDynamic first-time generation of files//Check if the local Office file exists, if it does not exist, and then return to the path for viewing stringWebpath =string. Format ("/generatefiles/office/{0}.htm", info.id); stringGeneratefilepath =Server.MapPath (Webpath); if(!fileutil.fileisexist (Generatefilepath)) { stringTemplateFile = bllfactory<fileupload>. Instance.getfilepath (info); TemplateFile= Path.Combine (System.AppDomain.CurrentDomain.BaseDirectory, Templatefile.replace ("\\","/")); if(ext = ="Doc"|| ext = ="docx") {Aspose.Words.Document doc=NewAspose.Words.Document (templatefile); Doc. Save (Generatefilepath, Aspose.Words.SaveFormat.Html); } Else if(ext = ="xls"|| ext = ="xlsx") {Workbook Workbook=NewWorkbook (templatefile); Workbook. Save (Generatefilepath, saveformat.html); } Else if(ext = ="ppt"|| ext = ="pptx") {TemplateFile= Templatefile.replace ("/","\\"); Presentationex pres=NewPresentationex (templatefile); Pres. 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.
The following is a closer look at the operational capabilities of the attachment Management module on the web framework.