word/excel/pdf files into HTML collation

Source: Internet
Author: User

During the project development process, the requirements involved a variety of documents converted to HTML or Web page easy to display format, and now the implementation of the way is sorted as follows:

First, use Jacob to convert Word,excel to HTML

"Jacob is a java-com middleware. You can invoke COM components and WIN32 libraries in Java applications through this component. ”

First download the Jacob package, JDK1.5 need to use the Jacob1.9 version (JDK1.6 not yet tested), and the previous Jacob1.7 difference is not

1, the compression package after decompression, Jacob.jar added to the libraries;

2, put the Jacob.dll to "Windows\System32" below.

It is to be noted that:

"When you start a Web server using the IDE, the system does not read Jacob.dll, such as starting Tomcat with MyEclipse, and you need to copy the DLL files to Jre\bin under the MyEclipse installation directory."

When the general system is not loaded into the Jacob.dll file, the error message is: "Java.lang.UnsatisfiedLinkError:no Jacob in Java.library.path" "

New class:

Java code

 public class Jacobutil {public static final int word_html = 8;

	public static final int word_txt = 7;

	public static final int excel_html = 44; /** * Word to HTML * @param docfile Word file full path * @param htmlfile HTML store path after conversion/public static void Wordtohtml (String Docfile, String htmlfile) {activexcomponent app = new Activexcomponent ("Word.Application");/start Word try {app
			. SetProperty ("Visible", new Variant (false));
			Dispatch docs = app.getproperty ("Documents"). Todispatch (); Dispatch doc = Dispatch.invoke (docs, "Open", Dispatch.method, new object[] {docfile, new Variant (FAL
			SE), new Variant (True)}, new Int[1]). Todispatch ();
			Dispatch.invoke (Doc, "SaveAs", Dispatch.method, new object[] {htmlfile, new Variant (word_html)}, new int[1]);
			Variant F = new Variant (FALSE);
		Dispatch.call (Doc, "Close", f);
		catch (Exception e) {e.printstacktrace ();
		finally {App.invoke ("Quit", new variant[] {}); }
	}

	/** * Excel to HTML * @param xlsfile Excel file full path * @param htmlfile after conversion HTML store path/public static void Exceltohtml (S 
			Tring Xlsfile, String htmlfile) {activexcomponent app = new Activexcomponent ("Excel.Application");/start Word try {
			App.setproperty ("Visible", new Variant (false));
			Dispatch excels = App.getproperty ("workbooks"). Todispatch (); Dispatch Excel = Dispatch.invoke (excels, "Open", Dispatch.method, new object[] {xlsfile, new Variant
			(false), new Variant (True)}, new Int[1]). Todispatch ();
			Dispatch.invoke (Excel, "SaveAs", Dispatch.method, new object[] {htmlfile, new Variant (excel_html)}, new int[1]);
			Variant F = new Variant (FALSE);
		Dispatch.call (Excel, "Close", f);
		catch (Exception e) {e.printstacktrace ();
		finally {App.invoke ("Quit", new variant[] {}); }
	}
}

I was looking for the conversion control, I found NetEase also reproduced a partial about the use of Jacob Help, but there have been a relatively serious error: String htmlfile = "C:\\aa";

Only specified at the folder level, the correct notation is string htmlfile = "c:\\aa\\xxx.html";

To this Word/excel conversion HTML is already almost, I believe you should be very clear:

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.