Procedure tform1.btn1click (Sender: tobject );
VaR
Excelapplication1, excelworkbook1: olevariant;
I: integer;
Begin
Try
Excelapplication1: = createoleobject ('excel. application ');
Excelworkbook1: = createoleobject ('excel. Sheet ');
Except
Application. MessageBox ('unable to open the xls file. Make sure you have installed excel .','',
Mb_ OK + mb_iconstop );
Exit;
End;
Excelworkbook1: = excelapplication1.workbooks. Add;
Excelapplication1.visible: = true;
Excelworkbook1.worksheets [1]. cells [1, 1]. Value: = 'id ';
Excelworkbook1.worksheets [1]. cells [1, 2]. Value: = 'username ';
Excelworkbook1.worksheets [1]. cells [1, 3]. Value: = 'Password ';
Try
For I: = 0 to lv1.items. Count-1 do
Begin
Excelworkbook1.worksheets [1]. cells [2 + I, 1]. Value: = lv1.items [I]. Caption;
Excelworkbook1.worksheets [1]. cells [2 + I, 2]. Value: = lv1.items [I]. subitems. Strings [0];
Excelworkbook1.worksheets [1]. cells [2 + I, 3]. Value: = lv1.items [I]. subitems. Strings [1];
End;
Except
End;
Excelapplication1: = unassigned; // release the variant variable
End;