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

📄 builddoc.java

📁 一个java与数据库连接的好例子
💻 JAVA
字号:
package com.eap;
import   com.jacob.activeX.*;   
import   com.jacob.com.*;   
import   java.io.File;   

public class BuildDoc{
	public static void HeadAppend(String sInputDoc,String sNewText){
		try{	
			
			ActiveXComponent   oWord   =   new   ActiveXComponent("Word.Application");   
  			oWord.setProperty("Visible",   new   Variant(false));   
  			Object   oDocuments   =   oWord.getProperty("Documents").toDispatch();   
  			Object   oDocument   =   Dispatch.call(oDocuments,   "Open",   sInputDoc).toDispatch();   
  			Object   oSelection   =   oWord.getProperty("Selection").toDispatch();   

			
			Dispatch.put(oSelection,   "Text",   sNewText);   //set oSelection with sNewText
  			Object   oFont   =   Dispatch.get(oSelection,   "Font").toDispatch();   //get oSelection's Font
  			Dispatch.put(oFont,   "Bold",   "1");   				  //set the Text of OSelection Bold
  			Dispatch.put(oFont,   "Italic",   "1");   				  //set the Text of OSelection Italic
 			Dispatch.put(oFont,   "Underline",   "0");   			  //set the Text of OSelection Underline	
  			Dispatch.put(oFont,   "Size",   "20");   				  //set the Text of OSelection Size
  			Dispatch.put(oFont,   "Color",   "1,0,0,0"); 			  //set the Text of OSelection Color

		
			Dispatch.invoke(oDocument, "SaveAs", Dispatch.Method, 
				              new Object[] {sInputDoc, new Variant(0)}, 
				              new int[1]);//save doc file
			Variant f = new Variant(false);	
			Dispatch.call(oDocument, "Close", f);
		}//try
		catch(Exception e){
			e.printStackTrace();
		}//catch
	}//testFindReplace

	public   static   void   main(String[]   args)   {   
                 	BuildDoc.HeadAppend("C:\\a.doc","I am a guy");   
                 	BuildDoc.HeadAppend("C:\\b.doc","I am a girl");
 	}//main  
}

⌨️ 快捷键说明

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