Recent

Author Topic: Excel export with range.value  (Read 946 times)

musicto

  • Newbie
  • Posts: 4
Excel export with range.value
« on: April 11, 2024, 11:59:08 am »
Good morning everyone,

After I wanted to transfer my Lazarus project (created with 2.0.10), which has grown over time, to the current Lazarus version, the following code for creating Excel documents no longer works.

Code Listed here very simply:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ToggleBox1Change(Sender: TObject);
  2. var
  3.   Range: olevariant;
  4.   arrData: olevariant;
  5.   x : integer;
  6.   varXLApp: olevariant;
  7.   varXLWb: olevariant;
  8. begin
  9.   arrData := VarArrayCreate([1, 10, 1, 10], varVariant);
  10.  for x := 1 to 10 do
  11.   begin
  12.       arrData[x, x ] := UTF8ToUTF16('Test');
  13.   end;
  14.   varXLApp := CreateOleObject('Excel.Application');
  15.   varXLWb := varXLApp.Workbooks.Add;
  16.   Range :=varXLWb.WorkSheets[1].Range[varXLWb.WorkSheets[1].Cells[1, 1],varXLWb.WorkSheets[1].Cells[10, 10]];
  17.   Range.Value :=  arrData;
  18.   varXLApp.Visible := True;
  19. end;    
  20.  

The error occurs at this point:
Code: Pascal  [Select][+][-]
  1.  Range.Value :=  arrData;
  2.  

EOleSysError: “Member not found”

As of Lazarus 2.0.12 something has changed there.
Before that it worked without any problems.
Before I have to deal with fpspreadsheet or another type of Excel export...can someone help me get my old code running?

Thanks and Regards

Sasha

musicto

  • Newbie
  • Posts: 4
Re: Excel export with range.value
« Reply #1 on: September 12, 2025, 09:49:31 am »
Range.Value :=  OleVarinat(arrData);

That was the trick.

 

TinyPortal © 2005-2018