JAVA中应用JCOM(一)

在JAVA中使用JCOM注意要点: 
(1)在你的lib下要有jcom-2.2.4.jar,jcom.dll。 

(2)要把jcom.dll同时放到你JDK的bin目录下或者放到系统盘的windows下(推荐放到JDK的BIN下) 

这段代码会建立到Excel的JCom接口,并把"Hello World"写入第一个单元格中。

import jp.ne.so_net.ga2.no_ji.jcom.ReleaseManager;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelApplication;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelRange;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbook;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorkbooks;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheet;
import jp.ne.so_net.ga2.no_ji.jcom.excel8.ExcelWorksheets;


public class TestSimple {

	public static void main(String[] args)throws Exception
	{
		ReleaseManager rm = new ReleaseManager();
		try{
			System.out.println("EXCEL is starting...");
			ExcelApplication excel = new ExcelApplication(rm);
			excel.Visible(true);
			ExcelWorkbooks xlBooks = excel.Workbooks();
			ExcelWorkbook xlBook = xlBooks.Add();
			ExcelWorksheets xlSheets = xlBook.Worksheets();
			ExcelWorksheet xlSheet = xlSheets.Item(1);
			ExcelRange xlRange = xlSheet.Cells();
			xlRange.Item(1, 1).Value("Hello,World!");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			rm.release();
		}
	}
}

你可能感兴趣的:(java,jcom)