给你一个我写得操作WORD的例子ActiveXComponent com;
try {
com=new ActiveXComponent("Word.Application");
com.setProperty("Visible", new Variant(false));
// OLE: set the default printer
if (uncName!=null && uncName.length()>0) {
com.setProperty("ActivePrinter", new Variant(uncName));
writeLog(out, clientID+" Word set active printer to: "+uncName);
} Object documents=com.getProperty("Documents").toDispatch();
Dispatch.call(documents,"Open",filename);
writeLog(out, clientID+" client's file has been opened: "+filename); // PrinterTrays
int lvFrontPageTray=0;
int lvDefaultTray=0;
if (frontPageTray!=null && frontPageTray.length()>0) {
lvFrontPageTray=Integer.parseInt(frontPageTray);
}
if (defaultTray!=null && defaultTray.length()>0) {
lvDefaultTray=Integer.parseInt(defaultTray);
}
Object ActiveDoc = com.getProperty("ActiveDocument").toDispatch();
Object PageSetup = Dispatch.get(ActiveDoc, "PageSetup").toDispatch();
Dispatch.put(PageSetup, "FirstPageTray", new Variant(lvFrontPageTray));
writeLog(out, clientID+" Word set FirstPageTray to: "+lvFrontPageTray);
Dispatch.put(PageSetup, "OtherPagesTray", new Variant(lvDefaultTray));
writeLog(out, clientID+" Word set OtherPagesTray to: "+lvDefaultTray);
com.invoke("PrintOut", new Variant[] {new Variant(false)});
writeLog(out, clientID+" client's file has sent to the printer"); Dispatch.call(ActiveDoc, "Save");
writeLog(out, clientID+" client's file has been saved.");
// Quite Microsoft Word
com.invoke("Quit", new Variant[] {});
writeLog(out, clientID+" client's word application has requested to quit");
} catch (Throwable e) {
writeLog(out, clientID+" client has error in printing the word document: "+e.getMessage());
e.printStackTrace();
return false;
}
try {
com=new ActiveXComponent("Word.Application");
com.setProperty("Visible", new Variant(false));
// OLE: set the default printer
if (uncName!=null && uncName.length()>0) {
com.setProperty("ActivePrinter", new Variant(uncName));
writeLog(out, clientID+" Word set active printer to: "+uncName);
} Object documents=com.getProperty("Documents").toDispatch();
Dispatch.call(documents,"Open",filename);
writeLog(out, clientID+" client's file has been opened: "+filename); // PrinterTrays
int lvFrontPageTray=0;
int lvDefaultTray=0;
if (frontPageTray!=null && frontPageTray.length()>0) {
lvFrontPageTray=Integer.parseInt(frontPageTray);
}
if (defaultTray!=null && defaultTray.length()>0) {
lvDefaultTray=Integer.parseInt(defaultTray);
}
Object ActiveDoc = com.getProperty("ActiveDocument").toDispatch();
Object PageSetup = Dispatch.get(ActiveDoc, "PageSetup").toDispatch();
Dispatch.put(PageSetup, "FirstPageTray", new Variant(lvFrontPageTray));
writeLog(out, clientID+" Word set FirstPageTray to: "+lvFrontPageTray);
Dispatch.put(PageSetup, "OtherPagesTray", new Variant(lvDefaultTray));
writeLog(out, clientID+" Word set OtherPagesTray to: "+lvDefaultTray);
com.invoke("PrintOut", new Variant[] {new Variant(false)});
writeLog(out, clientID+" client's file has sent to the printer"); Dispatch.call(ActiveDoc, "Save");
writeLog(out, clientID+" client's file has been saved.");
// Quite Microsoft Word
com.invoke("Quit", new Variant[] {});
writeLog(out, clientID+" client's word application has requested to quit");
} catch (Throwable e) {
writeLog(out, clientID+" client has error in printing the word document: "+e.getMessage());
e.printStackTrace();
return false;
}
解决方案 »
- jquerymobile里怎么设置LI标签的高度的形状
- 我将spring2.0 +hibernate3.0以前用的代码移植到最新版的spring2.5 +hibernate3.2后出现的错误,谁能帮忙,谢谢。
- 关于OUT.CLOSE()的一个疑问!!!!求解答
- 用jsp怎么产生随机密码和用户名称?
- 菜鸟求助 sql2000 jdbc驱动
- 2个月时间,请问学JAVA好,还是考网络工程师好
- 在线等,使用HttpURLConnection出现java.net.NoRouteToHostException: No route to host
- jspsmartmenu的问题!
- 怎样让客户端不显示internal servlet error页面
- 关于stuts2修改后加载列表的问题
- 在jsp中 如何记录用户点击的链接 点链接两种方法一是直接 一是用鼠标右健然后在请窗口打开 这两种都要记录 来着有分
- 我用JBOSS做的网站,当我按住f5刷新一个JSP页面出错.
十分感谢你的回复,但是我将你的代码拷下来运行后,出现了许多错误,原因是有许多参数没有声明,我是刚刚接触这类问题,希望你将整个程序的代码都贴出来,我将不胜感激,分数全给你。拜托了!!!