我创建了一个Java应用程序,它做了一些事情:
1.基于某些输入它会生成一些文本 - 在其他计算机上运行
2.基于输入,它修改excel文件 - 在其他计算机上工作
3.it从之前修改过的excel文件中运行一个宏 - 仅在我的计算机上运行
这是edis excel文件并运行宏的代码的一部分:
try {
File myFile = new File(atmScriptGeneratorPathTxt.getText() + "\\ATM Script Generator.xlsm");
FileInputStream fis = new FileInputStream(myFile);
XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
Cell myCell = null;
myCell= mySheet.getRow(2).getCell(2);
myCell.setCellValue(newRNCCDRFolderTxt.getText());
fis.close();
FileOutputStream output_file =new FileOutputStream(new File(atmScriptGeneratorPathTxt.getText() + "\\ATM Script Generator.xlsm"));
myWorkBook.write(output_file);
output_file.close();
myWorkBook.close();
String macroName = "'ATM Script Generator.xlsm'!ATM_Script_Generator.ATM_Script_Generator";
ComThread.InitSTA();
ActiveXComponent excel = new ActiveXComponent("Excel.Application");
try {
//This will open the excel if the property is set to true
Dispatch workbooks = excel.getProperty("Workbooks") .toDispatch();
Dispatch workBook = Dispatch.call(workbooks, "Open", myFile.getAbsolutePath()).toDispatch();
// Calls the macro
final Variant result = Dispatch.call(excel, "Run", new Variant(macroName));
System.out.println(result);
// Saves and closes
Dispatch.call(workBook, "Save");
com.jacob.com.Variant f = new com.jacob.com.Variant(true);
Dispatch.call(workBook, "Close", f);
} catch (Exception error) {
error.printStackTrace();
} finally {
excel.invoke("Quit", new Variant[0]);
ComThread.Release();
}
}
catch(Exception err) {
System.out.println(err);
}
}
这些是我用于此应用的库:
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
有谁知道为什么这个应用程序只能在我的电脑上运行?如果有任何人需要的信息以便找出问题所在,请告诉我。
答案 0 :(得分:0)
Jacob Libray包含两个.dll文件:
雅各布-1.18-x64.dll
雅各布-1.18-x86.dll
我将这两个.dll文件复制到:C:\ Program Files \ Java \ jre1.8.0_111 \ bin,然后就可以了。