Discussion:
Create Excel file
(too old to reply)
Andreas Hansson
2007-09-18 08:10:09 UTC
Permalink
Hi,

I'm currently rebuilding an old software made with Delphi 7 in D2006
and now I've come to an export to Excel function.

The old code(a part of it):
var
xls, wb, Range: OLEVariant;
arrData: Variant;
begin
...
xls := CreateOLEObject('Excel.Application');
wb := xls.Workbooks.Add;
...
end;

However this does not work in D2006.
Ive added "Variants, ComObj, ComCtrls" to uses, just as it was in D7

I get:
Undeclared identifier: 'CreateOLEObject'

When looking in the help file CreateOLEObject should be in the ComObj
unit, and I've alreade added that to uses.

I've tried to find examples but all are using CreateOLEObject.

Why can't I use this funktion?
Is there an another way?

I'm using D2006 arc and the app is an ECO app, if that has anything to
do with it.

Help most apriciated!
/Andreas
Mike Shkolnik
2007-09-18 19:31:21 UTC
Permalink
Hi,

you need add the ActiveX unit in uses clause

--
With best regards, Mike Shkolnik
Scalabium Software
http://www.scalabium.com
Post by Andreas Hansson
Hi,
I'm currently rebuilding an old software made with Delphi 7 in D2006
and now I've come to an export to Excel function.
var
xls, wb, Range: OLEVariant;
arrData: Variant;
begin
...
xls := CreateOLEObject('Excel.Application');
wb := xls.Workbooks.Add;
...
end;
However this does not work in D2006.
Ive added "Variants, ComObj, ComCtrls" to uses, just as it was in D7
Undeclared identifier: 'CreateOLEObject'
When looking in the help file CreateOLEObject should be in the ComObj
unit, and I've alreade added that to uses.
I've tried to find examples but all are using CreateOLEObject.
Why can't I use this funktion?
Is there an another way?
I'm using D2006 arc and the app is an ECO app, if that has anything to
do with it.
Help most apriciated!
/Andreas
Chris.Cheney
2007-09-19 07:44:53 UTC
Permalink
Post by Mike Shkolnik
Hi,
you need add the ActiveX unit in uses clause
Er, with Turbo Delphi Explorer (D2006), ActiveX isn't needed: by
experiment, the following compiles without error.

unit Unit1;

interface

uses
Forms, Classes, ComObj;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
CreateOleObject('');
end;

end.
Andreas Hansson
2007-09-19 12:26:26 UTC
Permalink
On 19 Sep 2007 00:44:53 -0700, "Chris.Cheney"
Post by Chris.Cheney
Post by Mike Shkolnik
Hi,
you need add the ActiveX unit in uses clause
Er, with Turbo Delphi Explorer (D2006), ActiveX isn't needed: by
experiment, the following compiles without error.
unit Unit1;
interface
uses
Forms, Classes, ComObj;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateOleObject('');
end;
end.
Strange! It does not work here. However I read yesterday that
CreateOLEObject does not exists in .NET
Chris.Cheney
2007-09-19 13:15:20 UTC
Permalink
Post by Andreas Hansson
Strange! It does not work here. However I read yesterday that
CreateOLEObject does not exists in .NET
Use the Delphi for Win32 personality instead!
Andreas Hansson
2007-09-19 14:23:23 UTC
Permalink
On 19 Sep 2007 06:15:20 -0700, "Chris.Cheney"
Post by Chris.Cheney
Post by Andreas Hansson
Strange! It does not work here. However I read yesterday that
CreateOLEObject does not exists in .NET
Use the Delphi for Win32 personality instead!
sorry but the app needs to be a .NET
Chris.Cheney
2007-09-19 15:44:23 UTC
Permalink
Post by Andreas Hansson
On 19 Sep 2007 06:15:20 -0700, "Chris.Cheney"
Post by Chris.Cheney
Post by Andreas Hansson
Strange! It does not work here. However I read yesterday that
CreateOLEObject does not exists in .NET
Use the Delphi for Win32 personality instead!
sorry but the app needs to be a .NET
BTW the ng borland.public.delphi.com.interop.dotnet might be a better place
to ask.
Chris.Cheney
2007-09-19 15:42:01 UTC
Permalink
Post by Andreas Hansson
On 19 Sep 2007 06:15:20 -0700, "Chris.Cheney"
Post by Chris.Cheney
Post by Andreas Hansson
Strange! It does not work here. However I read yesterday that
CreateOLEObject does not exists in .NET
Use the Delphi for Win32 personality instead!
sorry but the app needs to be a .NET
See the Developer Studio 2006 for .NET help on "Using COM Interop in
Managed Applications"
Mike Shkolnik
2007-09-19 17:39:06 UTC
Permalink
Post by Andreas Hansson
sorry but the app needs to be a .NET
In .NET you need use the next code instead CreateOLEObject:
var
txls: Type;
begin
txls := Type.GetTypeFromProgID('Excel.Application');
xls := Activator.CreateInstance(txls);
...
end;

Don't forget to include the next lines in uses-clause
System.Runtime.InteropServices, System.Reflection {$ELSE} , OleConst

--
With best regards, Mike Shkolnik
Scalabium Software
http://www.scalabium.com
***@scalabium.com
Andreas Hansson
2007-09-20 06:48:19 UTC
Permalink
On Wed, 19 Sep 2007 20:39:06 +0300, "Mike Shkolnik"
Post by Mike Shkolnik
Post by Andreas Hansson
sorry but the app needs to be a .NET
var
txls: Type;
begin
txls := Type.GetTypeFromProgID('Excel.Application');
xls := Activator.CreateInstance(txls);
...
end;
Don't forget to include the next lines in uses-clause
System.Runtime.InteropServices, System.Reflection {$ELSE} , OleConst
aaa Thanks!

Andreas Hansson
2007-09-19 12:25:34 UTC
Permalink
Hi!

Does not help :/

On Tue, 18 Sep 2007 22:31:21 +0300, "Mike Shkolnik"
Post by Mike Shkolnik
Hi,
you need add the ActiveX unit in uses clause
Loading...