开发者

Problem using JACOB to open an Excel spreadsheet generated using POI in Office 2010

开发者 https://www.devze.com 2023-01-29 06:15 出处:网络
At work we have a very old, but stable, applet that takes two excel spreadsheets (one acts as a template and the other as a data source). The template is created by the user in Excel, but the data sou

At work we have a very old, but stable, applet that takes two excel spreadsheets (one acts as a template and the other as a data source). The template is created by the user in Excel, but the data source is created using POI in a web application. Within the applet, both spreadsheets are opened via the Java/COM Bridge (JACOB), using the following method:

/**
 * Opens an excel workbook
 */
public Object openExcelWorkBook(ActiveXComponent xlActx, MailMergeArgs args, String dataSourceDocName, Object xlObj,
                                boolean isTemplate) {
  final String functionName = "openExcelWorkBook";
  Object activeWorkBookOj;
  String workbook;
  // get the workbooks object
  Object wrkBooksObj = Dispatch.get(xlActx, ExcelConstants.APPLICATION_WORKBOOKS).toDispatch();

  if ((!args.isTemplateExistsOnHost()) && (isTemplate)) {
    debug("Skipping opening template...", functionName);
  }
  // it is on host
  else {
    if (isTemplate) {
      workbook = getTemplateDocLoc(args);
    } else {
      if (!this.standaloneApp) {
        workbook = TMP_DIR + dataSourceDocName;
      } else {
        workbook = dataSourceDocName;
      }
    }

    debug("Opening workbook..." + workbook, functionName);
    Dispatch.call(wrkBooksObj, ExcelConstants.WORKBOOKS_OLE_OPEN, workbook).toDispatch();

  }

  debug("Locating workbook...", functionName);
  activeWorkBookOj = Dispatch.get(xlActx, ExcelConstants.APPLICATION_ACTIVEWORKBOOK).toDispatch();

  debug("End", functionName);
  return activeWorkBookOj;
}

From the applet log and an hs_err_pid file I know the template sheet is opened fine by JACOB, but the data sheet fails on the Dispatch.call.

From the h开发者_运维百科s_err_pid file:

> Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
> j  com.jacob.com.Dispatch.invokev(Ljava/lang/Object;Ljava/lang/String;III[Lcom/jacob/com/Variant;[I)Lcom/jacob/com/Variant;+0
> j  com.jacob.com.Dispatch.invokev(Ljava/lang/Object;II[Lcom/jacob/com/Variant;[I)Lcom/jacob/com/Variant;+27
> j  com.jacob.com.Dispatch.callN(Ljava/lang/Object;I[Ljava/lang/Object;)Lcom/jacob/com/Variant;+11
> j  com.jacob.com.Dispatch.call(Ljava/lang/Object;ILjava/lang/Object;)Lcom/jacob/com/Variant;+10
> j  com.perceptive.ctms.applets.ImpactApplet.openExcelWorkBook(Lcom/jacob/activeX/ActiveXComponent;Lcom/perceptive/ctms/applets/MailMergeArgs;Ljava/lang/String;Ljava/lang/Object;Z)Ljava/lang/Object;+122
> j  com.perceptive.ctms.applets.ImpactApplet.doExcelMailMerge(Lcom/perceptive/ctms/applets/MailMergeArgs;Ljava/lang/String;Ljava/lang/String;I)V+234
> j  com.perceptive.ctms.applets.ImpactApplet.runOrams(Lcom/perceptive/ctms/applets/MailMergeArgs;)V+320
> j  com.perceptive.ctms.applets.ImpactApplet.start()V+94
> j  sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run()V+1159
> j  java.lang.Thread.run()V+11
> v  ~StubRoutines::call_stub

We have only experienced this problem since testing on Office 2010.

We use POI 2.5.1 and JACOB 1.9 which have both moved on in the last few years, I intend to try upgrading them, but I would like to know if there are known issues with either project and Office 2010. Although POI 3.x supports OOXML our code needs to remain backwards compatible with earlier Office versions, so we would prefer to stick with generating using HSSF.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号