Importar Excel:
Código Delphi
[-]procedure TForm80.ExcelClick(Sender: TObject);
var
Excel, Sheet: OLEVariant;
CantRow, CantCol, i, j : Integer;
RangoMatriz: Variant;
FileName :string ;
begin
OpenDialog.Title := 'Excel a Importar ...';
OpenDialog.DefaultExt := 'xls';
OpenDialog.InitialDir := ExtractFilePath(Application.ExeName);
OpenDialog.FileName := '';
OpenDialog.Filter:='Archivos Excel (*.xls)|*.xls';
OpenDialog.FilterIndex:=1;
if(OpenDialog.Execute)then
begin
if(OpenDialog.FileName <> '')then
begin
FileName := OpenDialog.FileName;
Excel := CreateOleObject('Excel.Application');
Excel.Workbooks.Open(FileName);
Sheet := Excel.Workbooks[ExtractFileName(FileName)].WorkSheets[1];
Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
CantRow := Excel.ActiveCell.Row;
CantCol := Excel.ActiveCell.Column;
RangoMatriz := Excel.Range['A1', Excel.Cells.Item[CantRow,CantCol]].Value;
for i:=1 to CantRow do
begin
for j:=1 to CantCol do
begin
Table1.Append;
Table1Campo.AsString := trim(RangoMatriz[i,j]);
Table1.Post;
end; end; Excel.quit;
end;
end;
end;
Este Codigo, no es de mi autoria, deberia colocar la fuente, que la verdad, no la tengo en este momento.
Lo que hace es recorrer todas las celdas del Excel y cargar en una tabla.
La idea es ver como se hace y q cada uno lo reprograme a gusto y necesidad.
Saludos.