|
在用jacob生成PDF文件时,有些有问题的word或者excel文件,在打开的时候就弹出框,进程一直卡在那,让人点确定才能进行下一步,导致出现问题文件的时候需要到服务器里面去查看,进程卡在那里
public static boolean createPdf(String filePath,
String outFile) {
String officekind = filePath.substring(filePath.lastIndexOf("."));
File docFile = new File(filePath);
File pdfFile = new File(outFile);
ActiveXComponent wps = null;
String kind="";
String dockind="";
//word的获取wps的Documents对象,excel获取wps的Workbooks对象
if(officekind.lastIndexOf("xls") > 0||officekind.lastIndexOf("xlsx") > 0||officekind.lastIndexOf("et") > 0){
dockind = "et";
kind="Workbooks";
}else if(officekind.lastIndexOf("doc") > 0||officekind.lastIndexOf("docx") > 0||officekind.lastIndexOf("wps") > 0){
dockind = "wps";
kind="Documents";
}else if(officekind.lastIndexOf("ppt") > 0||officekind.lastIndexOf("pptx") > 0){
dockind = "wpp";
kind="Presentations";
}
try {
wps = new ActiveXComponent(dockind+".application");
ActiveXComponent doc = wps.invokeGetComponent(kind).invokeGetComponent("Open", new Variant(docFile.getAbsolutePath()),new Variant(true));
// JavaWindowsCommandUtil.killTask("et");
//转换为pdf
doc.invoke("ExportPdf", new Variant(pdfFile.getAbsolutePath()));
// doc.invoke("Close");
doc.invoke("Close", new Variant(false));
doc.safeRelease();
} catch (Exception e) {
e.printStackTrace();
return false;
}finally {
if (wps != null) {
wps.invoke("Quit", new Variant[]{});
wps.safeRelease();
}
}
return true;
}
但是我打开问题文件的时候会弹出框,如下: |
|
![]() |
这些问题文件即使不用jacob,直接本地用office打开也是会弹出框的,希望大家给个意见,希望不是针对文件进行单个处理,因为总不可能每次出现文件,就去找相应的文件进行修改!谢谢!
|
![]() 40分 |
ActiveXComponent wrdCom = new ActiveXComponent(“Word.Application”);
wrdCom.setProperty(“Visible”, new Variant(false)); wrdCom.setProperty(“DisplayAlerts”, new Variant(false)); 不知道有用没 |
![]() |
千言万语难表达,非常感谢,已经困扰我很久了! |


