Jacob-A JAVA-COM Bridge

Source: Internet
Author: User

I browsed the csdn forum today and accidentally saw a post about Jacob.
Name: use Java to convert Doc to HTML file...
Http://community.csdn.net/Expert/TopicView1.asp? Id = 5497442

Next, let's take a look at Jacob's website. This project is now released on sourceforge.net.
Http://sourceforge.net/projects/jacob-project/

Jacob is a JAVA-COM bridge that allows you to call COM automation components from Java. It uses JNI to make native callinto the COM and Win32 libraries.

Although the current project is not used yet, it is also good to know about it. You don't have to bother searching for it in the future.

Mark it.

Here are some examples and notes for the Jacob application, from the http://shuxudong.blog.hexun.com/7591618_d.html

 

After the DOC file is published, it may be browsed on the page. When browsing, the corresponding browsing tools must be loaded on the page, such: in this way, the corresponding browser tool must be installed on the client. If you want to convert a DOC file to an HTML file, you can save a lot of effort.

The above is the purpose of the following content, I hope you know.

 

/**
* @ Author sxd1
* @ Param paths
* @ Param savepaths
* @ See converts a Word document to HTML
*/
Public static void change (string paths, string savepaths ){
File [] lists = getfilelist (paths );
String pathss = new string ("");
// Search all files in the current directory
For (INT I = 0; I <lists. length; I ++ ){
If (lists [I]. isfile ()){
String filename = lists [I]. getname ();
// Determine whether the file is a DOC file
If (filename. endswith ("Doc ")){
Activexcomponent APP = new activexcomponent (
"Word. application"); // excel. Application
// Start WORD
String docpath = paths + filename;
String htmlpath = savepaths
+ Filename. substring (0, (filename. Length ()-4 ));
String infile = docpath;
// The Word file to be converted
String tpfile = htmlpath;
// Html file
Boolean flag = false;
Try {
App. setproperty ("visible", new variant (false ));
// Set word invisible
Object docs = app. getproperty ("events"). todispatch ();
Object Doc = Dispatch. Invoke (dispatch) docs, "open ",
Dispatch. method, new object [] {infile },
New int [1]). todispatch ();
// Open the Word file
Dispatch. Invoke (dispatch) Doc, "saveas ",
Dispatch. method, new object [] {tpfile,
New variant (8)}, new int [1]);
// Save it as a temporary file in HTML Format
Variant F = new variant (false );
Dispatch. Invoke (dispatch) Doc, "close ",
Dispatch. method, new object [] {new variant (
False)}, new int [1]);
Flag = true;
} Catch (exception e ){
E. printstacktrace ();
} Finally {
App. Invoke ("quit", new variant [] {});
}
System. Out. println ("converted! ");
}
} Else {
Pathss = paths;
// Enter the directory at the next level
Pathss = pathss + lists [I]. getname () + "/";
// Recursively traverse all directories
Change (pathss, savepaths );
}
}
}

The above code is the main body of the program.

/**
* @ Author sxd1
* @ Param dirname
* @ Return string []
* @ See: get the names of all objects in the given directory and put them in string [].
*/
Private Static file [] getfilelist (string dirname ){
File [] filelist = NULL;
File dir = new file (dirname );
If (dir. isdirectory ())
Filelist = dir. listfiles ();
Return filelist;
}

Note that the program is completed using the jadoc package. You need to complete the following work before writing a program. Because JDK does not have this package.

1. Download The jadoc. jar package. Visit http://danadler.com/jacb/and find version1.7.

2. Note that version1.7 contains the jadoc. jar and jadoc. DLL files, but only jadoc. Jar files and jardoc. DLL files must be downloaded again. : Http://tech.groups.yahoo.com/group/jacob-project/ “files” (of course, you must first register and join the group before you can enter the region to find and download the file "jacod_jer142fix_bin.zip.

3. Copy the downloaded jacod. jar file to/JRE/lib/ext of JDK, for example, C:/jdk1.5.0 _ 01/JRE/lib/Ext.

4. Copy the downloaded jacod. DLL to JDK's JRE/bin, for example, C:/jdk1.5.0 _ 01/JRE/bin.

Then you can run it. Wish it a success!

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1592453

Related Article

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.