Board index » delphi » Delphi5 --> Delphi2006

Delphi5 --> Delphi2006


2007-06-15 10:30:48 PM
delphi79
I'm migrating an application from Delphi5 to Delphi2006 and I've
encountered, a section of code where I am exporting a result set to Excel.
I've pasted a piece of my code.
Var
WorkBk: _WorkBook;
WorkSheet: _WorkSheet;
I, J, K, R, C, x : Integer;
TabGrid: Variant;
TotalList: OleVariant;
UpperBound: Integer;
lNumberFormat: String;
xIcid : Variant;
Begin
Try
StatusBar.Panels[0].Text:= 'Exporting to Excel...';
ProgressBar.Max:= StringGrid.RowCount;
UpperBound:= StringGrid.ColCount - 2;
TotalList:= VarArrayCreate([0,UpperBound - 1], varVariant);
For x:= 1 To UpperBound Do
TotalList[x - 1]:= 2 + x;
{Sending data to Excel...}
R:= StringGrid.RowCount;
C:= StringGrid.ColCount;
TabGrid := VarArrayCreate([0,(R - 1),0,(C - 1)],varVariant);
I:= 0;
Repeat
For J := 0 to (C - 1) do
TabGrid[I,J]:= StringGrid.Cells[J,I];
Inc(I,1);
ProgressBar.Position:= I;
Until
I>(R - 1);
Try
XLApp.Connect;
XLApp.WorkBooks.Add(xlWBatWorkSheet,0);
WorkBk := XLApp.WorkBooks.Item[1];
WorkSheet := WorkBk.WorkSheets.Get_Item(1) as _WorkSheet;
Worksheet.Range['A1',Worksheet.Cells.Item[R,C]].Value := TabGrid;
Worksheet.Range['A1',Worksheet.Cells.Item[R,C]].Value := TabGrid
This line used to work fine in Delphi 5, but now it is not compiling; E2029
'[' expected but ':=' found.
Regards
Brian
 
 

Re:Delphi5 --> Delphi2006

OK I have found what was wrong with this one...
Worksheet.Range['A1',Worksheet.Cells.Item[R,C]].Value[TabGrid];
however, now it is giving me 'type mismatch'!!! Have things changed so much
here??
Regards
Brian
"Brian Ellul" <XXXX@XXXXX.COM>writes
Quote
I'm migrating an application from Delphi5 to Delphi2006 and I've
encountered, a section of code where I am exporting a result set to Excel.
I've pasted a piece of my code.

Var
WorkBk: _WorkBook;
WorkSheet: _WorkSheet;
I, J, K, R, C, x : Integer;
TabGrid: Variant;
TotalList: OleVariant;
UpperBound: Integer;
lNumberFormat: String;

xIcid : Variant;
Begin
Try
StatusBar.Panels[0].Text:= 'Exporting to Excel...';
ProgressBar.Max:= StringGrid.RowCount;

UpperBound:= StringGrid.ColCount - 2;
TotalList:= VarArrayCreate([0,UpperBound - 1], varVariant);

For x:= 1 To UpperBound Do
TotalList[x - 1]:= 2 + x;

{Sending data to Excel...}
R:= StringGrid.RowCount;
C:= StringGrid.ColCount;
TabGrid := VarArrayCreate([0,(R - 1),0,(C - 1)],varVariant);
I:= 0;
Repeat
For J := 0 to (C - 1) do
TabGrid[I,J]:= StringGrid.Cells[J,I];
Inc(I,1);
ProgressBar.Position:= I;
Until
I>(R - 1);

Try
XLApp.Connect;
XLApp.WorkBooks.Add(xlWBatWorkSheet,0);
WorkBk := XLApp.WorkBooks.Item[1];
WorkSheet := WorkBk.WorkSheets.Get_Item(1) as _WorkSheet;
Worksheet.Range['A1',Worksheet.Cells.Item[R,C]].Value := TabGrid;

Worksheet.Range['A1',Worksheet.Cells.Item[R,C]].Value := TabGrid
This line used to work fine in Delphi 5, but now it is not compiling; E2029
'[' expected but ':=' found.

Regards
Brian


 

Re:Delphi5 --> Delphi2006

<<Brian Ellul:
'[' expected but ':=' found.
Quote
>
In later versions of Excel (starting with XP IIRC) the Value
property requires an RangeValueDataType argument. The
non-default values for RangeValueDataType are to do with XML,
but unless you need them you can supply EmptyParam instead.
Alternatively you can just use the Value2 property:
WS.Range['A1', 'A1'].Value[EmptyParam] := 1;
WS.Range['A1', 'A1'].Value2 := 1;
--
Deborah Pate (TeamB) delphi-jedi.org
TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
www.borland.com/newsgroups/genl_faqs.html