View office PPT Word Excel in a browser.

Source: Internet
Author: User
View office PPT Word Excel in a browser.

 

Previously, I wrote a simple method called "opening in IE and showing the download box during PPT viewing", but sharper, joelee, sapphire and other senior Xia's reminders and criticisms discovered that they had made a low-level error. That method was only used to open the pptfile in IE and maximize it, you can use the browser mode to block the downloaded dialog box. It does not play a major role. Once the client is not installed with Office PowerPoint, it cannot be opened.

So I deleted the article and found no new solutions on the Internet. I also did not find any ActiveX plug-ins that support browsing PPT in IE, besides, ie seems to have security restrictions on ActiveX plug-ins, which is not suitable.


On the Internet, I also see a way to open the office document in IE, excerpted here, the article address is http://blog.joycode.com/kaneboy/archive/2004/11/03/37889.aspx,

"

Word is opened in IE at the link of idea document. Many people may be interested in this question. Therefore, write a blog to give a rough description of the method.

After office2003 is installed, an ActiveX control is installed in the system, which is located in "program files/Microsoft Office/office11/owssupp. dll ". Through this control, JavaScript on the client page can activate the local office software to open and edit office documents. (In addition, Office XP should already contain this ActiveX Control .)

First, use a script to create a local object:

Opendocobj = new activexobject ("Sharepoint. opendocuments.2"); // to be compatible with Office XP, you can create "Sharepoint. opendocuments.1"

Then, call the corresponding method of opendocobj. For example, open an office document on the server:

Opendocobj. viewdocument ("http://www.abc.com/documents/sample.doc ");

The opendocobjobject uses different officedocument (.doc).xls0000.ppt) to open different programs (Word, Excel, and PowerPoint ). The viewdocument () method also has an overload signature, which allows us to manually specify which program to activate to open the document:

Opendocobj. viewdocument ("http://www.abc.com/documents/sample.doc", progid of the program to be activated );

How do I open the office program and edit files online?

Opendocobj. editdocument ("http://www.abc.com/documents/sample.doc ");

You can directly activate word, edit the document in word, and then click Save in word to save the file to the server. Note: In order for word to directly Save the edited document to the server, the Windows identity in the current context of the Web site must be in the corresponding directory of the server (that is, the physical path on the server corresponding to the virtual directory "http://www.abc.com/documents.pdf) you have the write permission. Otherwise, the SAVE action fails. After editing, editdocument () returns a bool value to indicate whether the editing operation is successful.

We can also open a document template on the server to create a new document:

Opendocobj. createnewdocument ("http://www.abc.com/documents/sampleTemplate.dot", "http://www.abc.com/documents ");

You can use /". The program used to create a new document depends on the template file type (for example, the. Dot template corresponds to the word ). You also need to pay attention to permissions when saving new documents. The createnewdocument () method returns a bool value to indicate whether the operation is successful.

The first parameter of the createnewdocument () method, in addition to using a template address, can also be directly specified as the progid of the client program to create a new document.

"

However, you also need to install MS Office on the client.

Later I thought that I could save the doc as a webpage when using word. I think the PPT document should also support this function, but it would be too annoying if I had to switch it manually every time, therefore, you can write a class to convert PPT to HTML. After each upload, use this class to convert PPT to HTML files.

The following are specific implementation classes:

Using system;
Using system. Collections. Generic;
Using system. text;
Using Microsoft. Office;
Using Microsoft. Office. InterOP. PowerPoint;
Namespace ppttohtml
{
Public class convertpowerpoint
{
Private Microsoft. Office. InterOP. PowerPoint. Application PPT;
///
/// Point to a specific file;
///
Private Microsoft. Office. InterOP. PowerPoint. Presentation pptfile;
Private string _ htmlfilename;

/// <Summary>
/// Path of the HTML file saved
/// </Summary>
Public String htmlfilename
{
Set
{
_ Htmlfilename = value;
}
}

Public convertpowerpoint ()
{
PPT = new application ();
}


/// <Summary>
/// Conversion process
/// </Summary>
/// <Param name = "pptfilename"> name of the PowerPoint file to be converted </param>
Public void convert (string pptfilename)
{

Pptfile = PPT. Presentations. Open (pptfilename, Microsoft. Office. Core. msotristate. msotrue, Microsoft. Office. Core. msotristate. msoctrue,
Microsoft. Office. Core. msotristate. msofalse );

Pptfile. saveas (_ htmlfilename, Microsoft. Office. InterOP. PowerPoint. ppsaveasfiletype. ppsaveashtml, Microsoft. Office. Core. msotristate. msoctrue );
Pptfile. Close ();

}
}
}

The converted HTML is as follows:


After passing the vs2005 test, of course this method is only an alternative solution. Before I find a better method, I will use it for the moment, it is convenient for users who do not have Office PowerPoint to directly browse the PPT we provide in the browser, and also provide the corresponding pptfile for users who have installed PowerPoint or who need it to download and use it by themselves.

At the same time, if you have more effective, you are welcome to give me some advice!

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.