Tema: excel
Ver Mensaje Individual
  #1  
Antiguo 22-05-2014
armando armando is offline
Miembro
 
Registrado: dic 2003
Posts: 74
Reputación: 23
armando Va por buen camino
excel

saludos.. necesito leer un hoja de excel a delphi xe2
encontre este codigo en delphi al limite
Código Delphi [-]
procedure TForm1.Button2Click(Sender: TObject);
var
  i: Integer;
  si: String;
  Hoja: _WorkSheet;
  Excel: Variant;
begin
 Excel.Workbooks.Open( ExtractFilePath( Application.ExeName ) + 'Hoja.xls',
  EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
  EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
  EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0 );

Hoja := Excel.Worksheets.Item[1] as _WorkSheet;
i := 2;
si := IntToStr( i );
repeat
  with ListView.Items.Add do
  begin
    SubItems.Add( Hoja.Range['A'+si,'A'+si].Value2 ); // Código
    SubItems.Add( Hoja.Range['B'+si,'B'+si].Value2 ); // Nombre
    SubItems.Add( Hoja.Range['C'+si,'C'+si].Value2 ); // CIF
    SubItems.Add( Hoja.Range['D'+si,'D'+si].Value2 ); // Saldo
  end;

  Inc( i );
  si := IntToStr( i );
until ( VarType( Excel.Range['A'+si,'A'+si].Value2 ) = VarEmpty );
Excel.Workbooks.Close( 0 );


end;

pero me marca un error
[DCC Error] FEXCEL1.pas(83): E2015 Operator not applicable to this operand type
operador no aplicable a este tipo de operado... en esta linea
Hoja := Excel.Worksheets.Item[1] as _WorkSheet;
sera la versión del delphi???
u/o algun otro método que conozcan..
gracias....
Responder Con Cita