⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testsheetcopy.java

📁 使用JCom的时候
💻 JAVA
字号:
import jp.ne.so_net.ga2.no_ji.jcom.*;

public class testSheetCopy {
	public static void main(String[] args) throws Exception {
		ReleaseManager rm = new ReleaseManager();
		try {
			System.out.println("EXCEL傪婲摦拞...");
			IDispatch xlApp = new IDispatch(rm, "Excel.Application");
			xlApp.put("Visible", new Boolean(true));
			IDispatch xlBooks = (IDispatch)xlApp.get("Workbooks");
			IDispatch xlBook = (IDispatch)xlBooks.method("Add",null);	// create new book
			IDispatch xlSheet = (IDispatch)xlApp.get("ActiveSheet");

			// set string to cell A1 .
			System.out.println("僙儖A1偵暥帤楍傪僙僢僩");
			Object[] arglist = new Object[1];
			arglist[0] = "A1";
			IDispatch xlRange = (IDispatch)xlSheet.get("Range",arglist);
			xlRange.put("Value","JCom (^o^)");

			// copy cell from A1 to B2 .
			// 僙儖傪僐僺乕偟偰傒傞丅扨堦僙儖
			System.out.println("僙儖A1偺撪梕傪B1偵僐僺乕");
			Object[] copyargs = new Object[1];
			copyargs[0] = (IDispatch)xlSheet.get("Range", new Object[] {"B2"});
			xlRange.method("Copy", copyargs);

			// copy cells from A1:B2 to C1:D2 .
			// 僙儖傪僐僺乕偟偰傒傞丅暋悢僙儖 A1:B2傪 C1:D2傊僐僺乕
			System.out.println("僙儖A1:B2偺撪梕傪C1:D2傊僐僺乕");
			IDispatch xlRangeA1B2 = (IDispatch)xlSheet.get("Range",new Object[] {"A1:B2"});
			copyargs = new Object[1];
			copyargs[0] = (IDispatch)xlSheet.get("Range", new Object[] {"C1"});
			xlRangeA1B2.method("Copy", copyargs);

			// copy sheet.
			// 僔乕僩傪僐僺乕偟偰傒傞
			System.out.println("僔乕僩傪僐僺乕");
			copyargs = new Object[2];
			copyargs[0] = null;
			copyargs[1] = xlSheet;
			xlSheet.method("Copy", copyargs);

			System.out.println("Hit [Enter] key to exit.");
			System.in.read();

			// quit.
			// 廔椆偝偣傞丅
			Object[] arglist3 = new Object[3];
			arglist3[0] = new Boolean(false);
			arglist3[1] = null;
			arglist3[2] = new Boolean(false);
			xlBook.method("Close", arglist3);
			xlApp.method("Quit", null);
		}
		catch(Exception e) { e.printStackTrace(); }
		finally { rm.release(); }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -