No TXLSReadWriteII defined - while exporting query to Excel

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
tomz
Posts: 1
Joined: Fri Oct 14, 2016 11:46 am

No TXLSReadWriteII defined - while exporting query to Excel

Post by tomz »

I am trying to export AmountQry to Excel, my code is:

Code: Select all

procedure TestExport;
var XLS: TXLSReadWriteII5;
    XLSDbRead: TXLSDbRead5;
    v: TExcelVersion;
begin
  XLS:=TXLSReadWriteII5.Create(Self);
  with XLS do begin
    Version := xvExcel2007;
    XLS.Filename:='D:\TMP_EXCEL\Mn.xlsx';
    DirectRead := False;
    DirectWrite := False;
    XLS.Add;
    //XLS.Sheets[0].AsString[0, 0] := 'test 1';
    //XLS.Sheets[0].AsString[0, 1] := 'test 2';
    //XLS.Sheets[0].AsString[1, 0] := 'test 3';
    //XLS.Write;
  end;
  XLSDbRead:=TXLSDbRead5.Create(Self);
  with XLSDbRead do begin
    Dataset := AmountQry;
    IncludeFieldnames := True;
    IndentDetailTables := True;
    ReadDetailTables := True;
    FormatCells := False;
    Row := 0;
    Sheet := 0;
    XLS := XLS;
  end;
  XLSDbRead.Read;
  XLS.Write;
end;
Unfortunately, XLSDbRead.Read gives error message 'XLSReadWriteII defined'. How can I remove this error message and proceed with export?
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: No TXLSReadWriteII defined - while exporting query to Excel

Post by larsa »

Hello

The problem is:

Code: Select all

with XLSDbRead do begin
    ...
    XLS := XLS;
  end;
The compiler translates this into:

Code: Select all

XLSDbRead.XLS := XLSDbRead.XLS;
That is, you is not assigning any TXLSReadWriteII5 object to TXLSDbRead5.

Conclusion: Don't use with statement. It only causes problems.
Lars Arvidsson, Axolot Data
Post Reply