jacob.dll不需要放到windows系统目录下,只需放到程序下即可
ActiveXComponent MsWordApp = new ActiveXComponent("Word.Application");//新文档
Dispatch selection = Dispatch.get(MsWordApp, "Selection").toDispatch();
Dispatch alignment = Dispatch.get(selection, "ParagraphFormat").toDispatch();
Dispatch.put(MsWordApp, "Visible", new Variant(true));//设置word是可见或不可见(true:显示;false:不显示)
Dispatch selection = Dispatch.get(MsWordApp, "Selection").toDispatch();//新的WORD面板
Dispatch.call(selection, "TypeParagraph"); //空一行
Dispatch.put(alignment, "Alignment", "3"); //(1:置中 2:靠右 3:靠左)
Dispatch.put(selection, "Text", str); //写入word的內容
Dispatch.put(font, "Bold", "0"); //字型租体(1:租体 0:取消租体)
Dispatch.put(font1, "Color", "1,0,0,0"); //字型顏色(1,0,0,0=>紅色 1,1,0,0=>棕色
Dispatch.put(font, "Italic", "1");//字型斜体(1:斜体 0:取消斜体)
Dispatch.call(image, "AddPicture", img);//写入图片
Dispatch.call(selection, "TypeText", title); //定入标题內容
Dispatch.put(font, "Size", new Variant(12)); // 小四
Dispatch.put(font1, "Name", new Variant("华文行楷"));//字体类型