try{
createNewDocument(url + "11.doc");
String[] command ={Registry.JNIRegistryTest()+"WINWORD.EXE", path};
Runtime.getRuntime().exec(command); }catch(Exception ee){
ee.printStackTrace();
}
public void createNewDocument(String filename) {
MsWordApp = new ActiveXComponent("Word.Application");
Dispatch documents = Dispatch.get(MsWordApp, "Documents").toDispatch();
document = Dispatch.call(documents, "Add").toDispatch();
insertText("2. ");
saveFileAs(filename);
closeDocument();
closeWord();
ComThread.Release();
}
为什么在有的机器上面word能打开,有的上面打不开,这是什么原因。程序的一些主要部分我贴在上面了。
createNewDocument(url + "11.doc");
String[] command ={Registry.JNIRegistryTest()+"WINWORD.EXE", path};
Runtime.getRuntime().exec(command); }catch(Exception ee){
ee.printStackTrace();
}
public void createNewDocument(String filename) {
MsWordApp = new ActiveXComponent("Word.Application");
Dispatch documents = Dispatch.get(MsWordApp, "Documents").toDispatch();
document = Dispatch.call(documents, "Add").toDispatch();
insertText("2. ");
saveFileAs(filename);
closeDocument();
closeWord();
ComThread.Release();
}
为什么在有的机器上面word能打开,有的上面打不开,这是什么原因。程序的一些主要部分我贴在上面了。
解决方案 »
- 讨论一下java中的反射机制
- 研究java源代码:AtomicLong是怎么实现同步的(jdk5.0新加的特性)
- 请写出下面代码的输出结果(14)
- 如何得到hashmap的key?
- 三个问题,一个100分
- (100分帖)哪位大牛知道sun公司网站哪里可以下到com.sun.rowset包所在的jar包及帮助文档?
- 用post方式发送数据到http服务器,为什么服务端收不到呀?谢谢大家,这个问题有点急!!
- 在JAVASCRIPT中执行APPLET实体方法,出错!!请帮帮忙
- 在嵌套语句块中局部变量的初始化问题!
- 我这个循环ip发送写出来 循环端口怎么加进去
- 十万火急求各位高手帮忙,要写一个能够自由添加文字的程序,文字最好能移动的,最后还要保存,我该怎么做呢?最好有代码,谢谢啦(十万火急)
- Java heap space
打印一下,
是的话,直接用java.awt.DeskTop这个类好了。
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.SWT;
import java.io.*;
import org.eclipse.swt.ole.win32.*;
public class Myfrm1 {
public Myfrm1() {
super();
}
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
OleFrame frame = new OleFrame(shell, SWT.NONE);
Menu bar = new Menu(shell, SWT.BAR);
MenuItem save = new MenuItem(bar,SWT.PUSH);
frame.setFileMenus(new MenuItem[] {save});
save.setText("保存");
shell.setMenuBar(bar);
shell.setText("swt window");
final File file = new File("D:\\eclipse\\文档\\test.doc");
final OleClientSite clientSite = new OleClientSite(frame, SWT.NONE, file); frame.setBounds(0,0,500,300);
save.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent e)
{ if (clientSite.isDirty()) {
/*判断文档是否被修改*/
File tempFile = new File(file.getAbsolutePath() + ".tmp"); /*创建该文件的临时文件*/
file.renameTo(tempFile);
/*将文件另存为临时文件*/
if (clientSite.save(file, true)){
// 如果保存成功,则删除临时文件
tempFile.delete();
} else {
// 否则,将临时文件另存为源文件
tempFile.renameTo(file);
}
} }
public void widgetSelected(SelectionEvent e)
{
if (clientSite.isDirty()) {
/*判断文档是否被修改*/
File tempFile = new File(file.getAbsolutePath() + ".tmp"); /*创建该文件的临时文件*/
file.renameTo(tempFile);
/*将文件另存为临时文件*/
if (clientSite.save(file, true)){
// 如果保存成功,则删除临时文件
tempFile.delete();
} else {
// 否则,将临时文件另存为源文件
tempFile.renameTo(file);
}
} }
});
clientSite.doVerb(OLE.OLEIVERB_PRIMARY );
shell.open( ); while(!shell.isDisposed( )) { if(!display.readAndDispatch( )) display.sleep( ); } display.dispose( );
clientSite.dispose();
frame.dispose();
}
}