Borland Delphi 7 TExcelApplication.Connect 适用于办公机器,但不适用于客户端

发布于 2024-12-27 14:01:11 字数 1214 浏览 1 评论 0原文

由于其局限性,我负责在我的办公室(Pascal)维护一些遗留代码,我编写了一个 delphi dll 来使用 TExcelApplication 访问 excel。

该 dll 在办公室完美运行,机器运行 Microsoft Office 2010、Windows 7 32 位和 64 位。客户端使用Novel Workstations、Windows XP、Microsoft 2007。dll

在遇到TExcelApplication.Connect时给出断点异常;命令。

除了我提到的差异之外,场景完全相同。

在 Novel Workstation 上访问 Microsoft Excel 是否有任何限制,或者是否有更好的方法来访问 Excel 文档?

注意:我只想读取Excel文档,它跨越多个行、列和电子表格,源Excel文档是*.xls 2007文档。

它的主要功能是实现与 Excel 文档的自动核对。

这是库代码片段

library MyLibrary;
uses
  SysUtils, Classes, Variants, Dialogs, StdCtrls, OleServer, ExcelXP, Windows;
Type
  PString=String[254];

Var
  ExcelObj : TExcelApplication;

Procedure XLSOPEN(THENAME:PSTRING;VAR Reslt:PSTRING); stdcall;
Begin
  If FileExists(THENAME) Then
  Begin
    ExcelObj := TExcelApplication.Create(nil);
    ExcelObj.ConnectKind := ckRunningOrNew;
    ExcelObj.Connect;

    If ExcelObj=nil Then
    Begin
      Result := 'Error : EXCEL couldnt be started!';
      Exit;
    End Else
    Begin
      Result := 'Successful';
      Exit;
    End;
  End Else
  Begin
    Result := 'Error : File '+THENAME+' does not exist!';
    Exit;
  End;
End;

Exports XLSOPEN Name 'XLSOpen';

Begin
End.

I'm in charge of maintaining some legacy code at my office (Pascal) due to it's limitations, I've written a delphi dll to access excel using TExcelApplication.

The dll works perfectly at the office, the machines are running Microsoft Office 2010, Windows 7 32-Bit and 64-Bit. The client is using Novel Workstations, Windows XP, Microsoft 2007.

The dll gives a breakpoint exception when encountering the TExcelApplication.Connect; command.

Other than the differences that I've mentioned, the scenario's are exactly the same.

Are there any limitations regarding accessing Microsoft Excel on a Novel Workstation, alternatively, is there a better way to access Excel documents?

Note: I just want to read from the Excel document, it spans multiple rows, columns and spreadsheets, the source Excel documents are *.xls 2007 documents.

It's primary function was to enable automated reconciliation against the Excel document.

Here is a snippet of the library code

library MyLibrary;
uses
  SysUtils, Classes, Variants, Dialogs, StdCtrls, OleServer, ExcelXP, Windows;
Type
  PString=String[254];

Var
  ExcelObj : TExcelApplication;

Procedure XLSOPEN(THENAME:PSTRING;VAR Reslt:PSTRING); stdcall;
Begin
  If FileExists(THENAME) Then
  Begin
    ExcelObj := TExcelApplication.Create(nil);
    ExcelObj.ConnectKind := ckRunningOrNew;
    ExcelObj.Connect;

    If ExcelObj=nil Then
    Begin
      Result := 'Error : EXCEL couldnt be started!';
      Exit;
    End Else
    Begin
      Result := 'Successful';
      Exit;
    End;
  End Else
  Begin
    Result := 'Error : File '+THENAME+' does not exist!';
    Exit;
  End;
End;

Exports XLSOPEN Name 'XLSOpen';

Begin
End.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情空心 2025-01-03 14:01:11

您需要将 ActiveX 添加到您的使用列表中,并使用 CoInitialize(nil); 来初始化 ActiveX 组件。原因是因为Application->Initialize初始化了组件,现在它是一个dll,你必须在加载组件时手动初始化组件,并在卸载dll时使用UnCoInitizlise;

USES ActiveX, Windows;

INITIALIZATION
  CoInitialize(nil);
FINALIZATION
  UnCoInitialize;

You need to add ActiveX to your uses list and use CoInitialize(nil); to initialize the ActiveX components. The reason for this is because Application->Initialize initializes the components, now that it's a dll, you have to manually initialize the component when it's loaded and use UnCoInitizlise; when unloading the dll.

USES ActiveX, Windows;

INITIALIZATION
  CoInitialize(nil);
FINALIZATION
  UnCoInitialize;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文