简体   繁体   English

运行VBA宏的Java应用只能在我的计算机上运行

[英]Java app that runs an VBA macro works only on my computer

I created a Java app that does a few things: 我创建了一个执行以下操作的Java应用程序:

1.based on some input it generates some text - works on other computers 1.基于一些输入,它会生成一些文本-在其他计算机上可以使用

2.based on an input it modifies a excel file - work on other computers 2.根据输入修改Excel文件-在其他计算机上工作

3.it runs a macro from the excel file that it modified earlier - works only on my computer 3.它从先前修改的excel文件运行一个宏-仅在我的计算机上工作

This is the part of the code that edis the excel file and runs the macro: 这是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);
    }
}

These are the libraries that I am using for this app: 这些是我正在为此应用程序使用的库:

import org.apache.poi.ss.usermodel.Cell; 导入org.apache.poi.ss.usermodel.Cell;

import org.apache.poi.xssf.usermodel.XSSFSheet; 导入org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook; 导入org.apache.poi.xssf.usermodel.XSSFWorkbook;

import com.jacob.activeX.ActiveXComponent; 导入com.jacob.activeX.ActiveXComponent;

import com.jacob.com.ComThread; 导入com.jacob.com.ComThread;

import com.jacob.com.Dispatch; 导入com.jacob.com.Dispatch;

import com.jacob.com.Variant; 导入com.jacob.com.Variant;

Does anyone knows why this app works only on my computer? 有谁知道为什么这个程序只能在我的计算机上工作? If there is any more info that someone needs in order to figure out what is the problem, let me know. 如果有人需要更多信息以找出问题所在,请告诉我。

Jacob Libray contains two .dll files: Jacob Libray包含两个.dll文件:

jacob-1.18-x64.dll jacob-1.18-x64.dll

jacob-1.18-x86.dll jacob-1.18-x86.dll

I copied this two .dll files to: C:\\Program Files\\Java\\jre1.8.0_111\\bin and it worked after. 我将这两个.dll文件复制到:C:\\ Program Files \\ Java \\ jre1.8.0_111 \\ bin,此后它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java和JNI-加载dll库仅在我的计算机上有效 - Java and JNI - Loading dll libraries only works on my computer .jar仅在我的计算机上工作,classnotfoundexception在其他计算机上工作 - .jar works only on my computer, classnotfoundexception on others 是什么导致我的教授在运行程序时出现异常,但在我的计算机上可以正常工作? - What is causing my professor to get an exception when she runs my program but it works fine on my computer? Java Applet仅在我的计算机上工作吗? - Java Applet work only on my computer? Java YearMonth 不会解析,但只能在我的电脑上解析? - Java YearMonth will not parse, but only on my computer? 我的Java程序只运行一次,然后停止 - My java program only runs once, then stops 使用两个循环,但只有一个循环运行。 计算机科学导论(Java) - Using two loops but only one loop runs through. Intro to computer science.(Java) 我可以制作一个只在我的电脑上运行的 Java 程序吗? - Can i make a java program to run only on my computer? Java程序在一台计算机上运行,​​但不在另一台计算机上运行 - Java program runs on one computer but not the other Java,只有第一个 for 语句在我的代码中有效 - Java, Only the first for statement works in my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM