Use jcom and JXL in Java to note the main points:
(1) You must have Jdom-1.0.jar,jxl-2.5.5.jar,jcom-2.2.4.jar,jcom.dll under your lib.
(2) to put the Jcom.dll in your JDK's Bin directory or on the system disk under Windows (recommended to the JDK under the bin)
After putting all the jar packs in place, start writing the utility class in the application (stating that the IDispatch object is in the jcom and that the following throws a Jcomexception exception)
(1) First of all, you should determine whether a pass in the path is word or Excel or other dongdong.
if(path.endsWith(".doc")){
......
}
Note: If the Excel suffix is ". xls";
(2) Then you need to have two objects:
ReleaseManager rm = new ReleaseManager();
IDispatch xlsApp=null;
Note: Releasemanager is equivalent to a container that interacts with all jcom on your machine, and according to the parameters you pass on, he will look for all the jcom that you can do on your machine.
IDispatch can be understood as an object, all the Dongdong are objects;
(3) You have to let him know that you want to interact with Excel.
Xlsapp = new IDispatch (rm, "Excel.Application");
(4) next to get a workbooks (work thin)
IDispatch Excel = (IDispatch) xlsapp.get ("workbooks");
(5) To set whether the current object is visible
Xlsapp.put ("Visible", new Java.lang.Boolean (false));
(6) To open after getting the workbook
IDispatch workbook = (IDispatch) excel.method ("Open", new object[] {FilePath (path that Excel stores)});
(7) Determine if the file exists if it exists then delete
File f = new File(outPath);
if (f.exists())
f.delete();
(8) Save the workbook as
Workbook.method ("SaveAs", new object[] {outpath, new Integer (9)});
(9) Get all worksheets under a workbook (workbook) (Sheets)
IDispatch sheets = (IDispatch) workbook.get ("sheets");
Note: The obtained is an array;