tuskinhu

Ler XLS pra StringGrid

Aug 9th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.85 KB | None | 0 0
  1. uses comobj;
  2.  
  3. var
  4.   Excel: Variant;
  5.   Linha, CN: Integer;
  6.   arq : TFileName;
  7. begin
  8.   Excel := CreateOleObject('Excel.Application');
  9.   Excel.Visible := false;
  10.   OpenDialog1.Execute;
  11.   arq := OpenDialog1.FileName;
  12.   Excel.WorkBooks.Open(arq);
  13.  
  14.   Linha:=3;
  15.  
  16.   StringGrid1.RowCount := 1;
  17.   StringGrid1.ColCount := 4;
  18.   StringGrid1.Cells[1,0] := 'BOLETO';
  19.   StringGrid1.Cells[2,0] := 'VALOR';
  20.  
  21.   CN := 1 ;
  22.  
  23.   While Linha < 1000 Do
  24.   begin
  25.     StringGrid1.RowCount := CN;
  26.     StringGrid1.Cells[0,CN] := IntToStr(CN);
  27.     StringGrid1.Cells[1,CN] := Excel.WorkBooks[1].Sheets[1].Cells[LINHA,1];
  28.     StringGrid1.Cells[2,CN] := Excel.WorkBooks[1].Sheets[1].Cells[LINHA,3];
  29.  
  30.     IF Length(StringGrid1.Cells[1,CN]) = 0 THEN
  31.     begin
  32.       Excel.quit ;
  33.       EXIT ;
  34.     end ;
  35.    
  36.     CN := CN + 1 ;
  37.     linha := linha + 2 ;
  38.   end;
  39.  
  40.  end;
Advertisement
Add Comment
Please, Sign In to add comment