Open word online

Source: Internet
Author: User

Http://www.68design.net/Development/JSP/19165-1.html

Http://www.ninedns.com/JSP/200742218370011634.html

Http://wenwenye820526.javaeye.com/blog/352457

Http://www.javaeye.com/topic/333676

I'm reading it. No result is returned yet.

----

Find a free plug-in weboffices that opens word online. Yes: http://www.dianju.cn/p/weboffice/

Control weboffice_v6.0.4.2.cab is http://www.dianju.cn/p/weboffice/file/weboffice_v6.0.4.2.cab#version=6,0,4,2

------------------------

Hey, finally solved the problem. With the help of the Jacob. Jar operation offices, first save the file as an HTM file and then output the HTM file stream to the page.

Http://hi.baidu.com/seejava/blog/item/cf56c2a2a56c72a1caefd0e2.html

The user requested that the uploaded Doc and XLS files should not be downloaded. When you directly request a file in a browser, there will always be a downloading prompt. Is it okay to convert the doc to HTML? The idea is ready. Google gave me a way to convert it. Haha.
In this example, the Word and Excel files are converted into HTML files under JDK 6.
1. The jacob package is required first. You can.
2. decompress the file jacob. jar (put it directly in classpath) and put it in system32.
3. It is said that if it is win2003, you still need to install something. Http://www.microsoft.com/downloads/details.aspx? Familyid = 200B2FD9-AE1A-4A14-984D-389C36F85647 & amp; displaylang = en & displaylang = en
But I do not need xp.

The Demo code is as follows:

Package com. hz. util;
Import org. apache. commons. logging. Log;
Import org. apache. commons. logging. LogFactory;
Import com. hz. dao. NoticeDAO;
Import com. jacob. activeX. ActiveXComponent;
Import com.jacb.com. Dispatch;
Import com.jacb.com. Variant;
Public class Jacob2Html
{
Private static final Log log = LogFactory. getLog (jacb2html. class );
/**
* Convert PowerPoint to HTML
* @ Param pptpath the full path of the PowerPoint File
* @ Param htmlfile: HTML storage path after conversion
*/
Public static void ppttohtml (string pptpath, string htmlpath)
{
Activexcomponent offcom = new activexcomponent ("PowerPoint. application ");
Try
{
Offcom. setproperty ("visible", new variant (true ));
Dispatch excels = offCom. getProperty ("Presentations"). toDispatch ();
Dispatch excel = Dispatch. invoke (excels,
"Open", Dispatch. Method, new Object [] {pptPath, new Variant (false), new Variant (false)}, new int [1]). toDispatch ();
Dispatch. invoke (excel, "SaveAs", Dispatch. Method, new Object [] {
HtmlPath, new Variant (12)}, new int [1]);
Variant f = new Variant (false );
Dispatch. Call (Excel, "close ");
}
Catch (exception E)
{
E. printstacktrace ();
}
Finally
{
Offcom. Invoke ("quit", new variant [] {}); comthread. Release ();
}
}


/**
* Convert Word to HTML
* @ Param wordpath: full path of the Word file
* @ Param htmlpath: HTML storage path generated
*/
Public static void wordtohtml (string wordpath, string htmlpath)
{
Activexcomponent offcom = new activexcomponent ("word. application ");
Try
{
Offcom. setproperty ("visible", new variant (false ));
Dispatch wordDis = offCom. getProperty ("Documents"). toDispatch ();
Dispatch doc = Dispatch. invoke (wordDis,
"Open", Dispatch. Method, new Object [] {wordPath, new Variant (false ),
New Variant (true)}, new int [1]). toDispatch ();
Dispatch. invoke (doc, "SaveAs", Dispatch. Method, new Object [] {
Htmlpath, new variant (8)}, new int [1]);
Variant F = new variant (false );
Dispatch. Call (Doc, "close", F );
}
Catch (exception E)
{
E. printstacktrace ();
}
Finally
{
OffCom. invoke ("Quit", new Variant [] {});
}
}

/**
* Convert EXCEL to HTML
* @ Param xlsfile full EXCEL file path
* @ Param htmlfile: HTML storage path after conversion
*/
Public static void excelToHtml (String excelPath, String htmlPath)
{
ActiveXComponent offCom = new ActiveXComponent ("Excel. Application ");
Try
{
OffCom. setProperty ("Visible", new Variant (false ));
Dispatch excels = offCom. getProperty ("Workbooks"). toDispatch ();
Dispatch excel = Dispatch. invoke (excels,
"Open", Dispatch. Method, new Object [] {excelPath, new Variant (false), new Variant (true)}, new int [1]). toDispatch ();
Dispatch. invoke (excel, "SaveAs", Dispatch. Method, new Object [] {
Htmlpath, new variant (44)}, new int [1]);
Variant F = new variant (false );
Dispatch. Call (Excel, "close", F );
}
Catch (exception E)
{
E. printstacktrace ();
}
Finally
{
Offcom. Invoke ("quit", new variant [] {}); comthread. Release ();
}
}


Public static void main (string [] ARGs)
{
// Exceltohtml ("C:/FTC/kk.xls", "C:/FTC/kkk.html ");
// Wordtohtml ("C:/FTC/gdf.doc", "C:/FTC/gdf.html ");
Ppttohtml ("C:/FTC/jj.ppt", "C:/FTC/jjh.html ");
}
}
 

----------------------------------

----------

In a word, Jacob generates HTML in the project folder and opens it through the link.

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.