Excel automation

8625.untitled.bmp (294 KB)

8625.untitled.bmp (294 KB)

I am trying to create a report to export to excel by automation. I have copied certain function from table 370. But I’m getting this error. Can anybody help.?

Hi,

This type OLE control error normally come when you export huge data.

Preview the report with Short time period, for e.g. If you have Date filter in report then run for 1Months-6Month and try it.

Thanks

Abhishek

Run debugger and check the parameter values being passed to the RANGE statement(s). Likely they are invalid.

Hi,

There are just 8 records in that table. And this error appears when XlApp.Range() is called for the first time.

The Range statement expects a cell range. Verify that you are passing a valid cell range. I had this error recently. Turned out I was passing a cell position as ‘1A’ instead of ‘A1’.

No, it is A1.

That was just an example. There could be something else wrong with the format of the values being passed to the RANGE statement. Run the debugger and check exactly what is being passed. Most of these exceptions are cause by invalid parameters.

PROPERTIES
{
TransactionType=Snapshot;
OnPreReport=BEGIN
CreateBook;
END;

OnPostReport=BEGIN

XlApp.Visible(TRUE);
XlApp.UserControl(TRUE);
CLEAR(XlApp);
END;

}
DATAITEMS
{
{ PROPERTIES
{
DataItemTable=Table60011;
OnAfterGetRecord=BEGIN
PrintCell(ColNo,RowNo,‘test’,1,1,TRUE,TRUE,TRUE);
END;

}
SECTIONS
{
{ PROPERTIES
{
SectionType=Body;
SectionWidth=12000;
SectionHeight=846;
}
CONTROLS
{
}
}
}
}
}
REQUESTFORM
{
PROPERTIES
{
Width=9020;
Height=3410;
}
CONTROLS
{
}
}
REQUESTPAGE
{
PROPERTIES
{
}
CONTROLS
{
}
}
CODE
{
VAR
XlApp@1000000000 : Automation “{00020813-0000-0000-C000-000000000046} 1.6:{00024500-0000-0000-C000-000000000046}:‘Microsoft Excel 12.0 Object Library’.Application”;
XlWrkbk@1000000001 : Automation “{00020813-0000-0000-C000-000000000046} 1.6:{00020819-0000-0000-C000-000000000046}:‘Microsoft Excel 12.0 Object Library’.Workbook”;
Xlwrksht@1000000002 : Automation “{00020813-0000-0000-C000-000000000046} 1.6:{00020820-0000-0000-C000-000000000046}:‘Microsoft Excel 12.0 Object Library’.Worksheet”;
ColumnName@1000000003 : Text[30];
x@1000000004 : Integer;
grecexcelbuffer@1000000005 : Record 370;
ColNo@1000000006 : Integer;
RowNo@1000000007 : Integer;

PROCEDURE CreateBook@1000000000();
BEGIN
IF NOT CREATE(XlApp,TRUE) THEN
ERROR(’’);
XlApp.Visible(FALSE);
XlWrkbk := XlApp.Workbooks.Add;
Xlwrksht := XlWrkbk.Worksheets.Add;

ColNo:=1;
RowNo:=1;
END;

PROCEDURE PrintCell@1000000001(Column@1000000000 : Integer;Row@1000000001 : Integer;Text@1000000006 : Text[30];IncCol@1000000002 : Integer;IncRow@1000000003 : Integer;IsBold@1000000004 : Boolean;IsItalic@1000000005 : Boolean;IsUnderline@1000000007 : Boolean);
VAR
xlUnderlineStyleSingle@1000000008 : Text[30];
BEGIN
x:=Column;
ColID();
Xlwrksht.Range(FORMAT(ColumnName[Column])+FORMAT(Row)).Value:=COPYSTR(Text,1,1);
IF IsBold THEN
Xlwrksht.Range(FORMAT(ColumnName[Column])+FORMAT(Row)).Font.Bold :=TRUE;
IF IsItalic THEN
Xlwrksht.Range(FORMAT(ColumnName[Column])+FORMAT(Row)).Font.Italic :=TRUE;
IF IsUnderline THEN
Xlwrksht.Range(FORMAT(ColumnName[Column])+FORMAT(Row)).Font.Underline := TRUE;

ColNo+=IncCol;
RowNo+=IncRow;
END;

PROCEDURE ColID@1000000002();
VAR
i@1000000003 : Integer;
y@1000000002 : Integer;
c@1000000001 : Char;
t@1000000000 : Text[30];
BEGIN
ColumnName := ‘’;
WHILE x > 26 DO BEGIN
y := x MOD 26;
IF y = 0 THEN
y := 26;
c := 64 + y;
i := i + 1;
t[i] := c;
x := (x - y) DIV 26;
END;
IF x > 0 THEN BEGIN
c := 64 + x;
i := i + 1;
t[i] := c;
END;
FOR x := 1 TO i DO
ColumnName[x] := t[1 + i - x];
END;

I don’t spot anything right off in code. That’s why I suggest running the debugger as the data may point you to the issue.

i have tried that few times. Error is fired at the first call of function Printcell

Have you set a brealpoint on that PrintCell statement? So the debugger stops before the error and you can verify values. Or add some messages into the code to show the variuable values.