Borland Delphi 7 TExcelApplication.Connect 适用于办公机器,但不适用于客户端
由于其局限性,我负责在我的办公室(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
ActiveX
添加到您的使用列表中,并使用CoInitialize(nil);
来初始化 ActiveX 组件。原因是因为Application->Initialize初始化了组件,现在它是一个dll,你必须在加载组件时手动初始化组件,并在卸载dll时使用UnCoInitizlise;
。You need to add
ActiveX
to your uses list and useCoInitialize(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 useUnCoInitizlise;
when unloading the dll.