Fórum Numero de Linhas e Colunas do Excel - Usando OLE #325454
17/07/2006
0
eu to carregando um arquivo excel..usando OLE..
Excel := CreateOleObject(´Excel.Application´); Excel.Visible := false; Excel.WorkBooks.Open(wOri);
alguem saber me dizer como eu pego o numero de linhas e o numero de colunas??
nem sei c ísso é possivel..mas por exemplo...
o excel tem la um numero denorme de linhas..mas eu só usei 37..
tem como ele me retornar esse numero..
e a mesma coisa com as colunas...está sendo usando só 28 colunas...
tem como fazer isso?? ja tentei e não achei nada..se alguem puder me ajudar....
abraço a todos
Alansvieceli
Curtir tópico
+ 0Posts
17/07/2006
Cpd_arim
Excel : Variant;
i,j : Integer;
begin
Excel := CreateOleObject(´Excel.Application´);
Excel.Visible := True;
Excel.WorkBooks.Add;
for i := 0 to 3 do
for j := 0 to 6 do
Excel.Workbooks[1].Sheets[1].Cells[j+1,i+1] := StringGrid1.Cells[i,j];
Excel.Workbooks[1].Sheets[1].Cells[8,1] := ´=sum(a2:a7)´;
Excel.Workbooks[1].Sheets[1].Cells[8,2] := ´=sum(b2:b7)´;
Excel.Workbooks[1].Sheets[1].Cells[8,3] := ´=sum(c2:c7)´;
Excel.Workbooks[1].Sheets[1].Cells[8,4] := ´=sum(d2:d7)´;
for i := 0 to 3 do
StringGrid2.Cells[i,0] := Excel.Workbooks[1].Sheets[1].Cells[8,i+1];
Excel.Workbooks[1].SaveAs(´teste.xls´);
Excel.Quit;
end;
Gostei + 0
17/07/2006
Alansvieceli
o q não pode é ter o valores de linhas e colonas fixas..pq eu não sei quais são.... a tabela Excel é gerada automatica por um exportador lá...
não sei quantas linhas nem colunas..isso pode variar...
por isso não posso usar
or i := 0 to 3 do for j := 0 to 6 do Excel.Workbooks[1].Sheets[1].Cells[j+1,i+1] := StringGrid1.Cells[i,j]; Excel.Workbooks[1].Sheets[1].Cells[8,1] := ´=sum(a2:a7)´; Excel.Workbooks[1].Sheets[1].Cells[8,2] := ´=sum(b2:b7)´; Excel.Workbooks[1].Sheets[1].Cells[8,3] := ´=sum(c2:c7)´; Excel.Workbooks[1].Sheets[1].Cells[8,4] := ´=sum(d2:d7)´;
tinha q ser mais ou menos assim..
or i := 0 to Excel.Workbooks[1].Sheets[1].Lines.Count do for j := 0 to Excel.Workbooks[1].Sheets[1].Colluns.Count do Excel.Workbooks[1].Sheets[1].Cells[j+1,i+1] := StringGrid1.Cells[i,j]; Excel.Workbooks[1].Sheets[1].Cells[8,1] := ´=sum(a2:a7)´; Excel.Workbooks[1].Sheets[1].Cells[8,2] := ´=sum(b2:b7)´; Excel.Workbooks[1].Sheets[1].Cells[8,3] := ´=sum(c2:c7)´; Excel.Workbooks[1].Sheets[1].Cells[8,4] := ´=sum(d2:d7)´;
mais esses
[b:05eb7228c8]Excel.Workbooks[1].Sheets[1].Lines.Count[/b:05eb7228c8]
[b:05eb7228c8]Excel.Workbooks[1].Sheets[1].Colluns.Count[/b:05eb7228c8]
Não existem...
[/b]
Gostei + 0
19/07/2006
Alansvieceli
preciso de ajuda...
Gostei + 0
21/07/2006
Alansvieceli
...help me...
Gostei + 0
26/07/2006
Alansvieceli
Gostei + 0
26/07/2006
Jáder Medeiros
Function Colunas(pFile,pPlan: String): Integer; var XLApp, Sheet: Variant; begin Result := 0; XLApp:= CreateOleObject(´Excel.Application´); try XLApp.WorkBooks.Open(pFile,0,True); Sheet := XLApp.Workbooks[1].WorkSheets[pPlan]; Result := Sheet.Cells.SpecialCells(11).Column finally XLApp.Quit end end; Function Linhas(pFile,pPlan: String): Integer; var XLApp, Sheet: Variant; begin Result := 0; XLApp:= CreateOleObject(´Excel.Application´); try XLApp.WorkBooks.Open(pFile,0,True); Sheet := XLApp.Workbooks[1].WorkSheets[pPlan]; Result := Sheet.Cells.SpecialCells(11).Row finally XLApp.Quit end end;
Gostei + 0
07/08/2006
Alansvieceli
abraços..
Gostei + 0