Ver Mensaje Individual
  #2  
Antiguo 14-04-2005
lgarcia lgarcia is offline
Miembro
 
Registrado: jul 2004
Posts: 479
Reputación: 20
lgarcia Va por buen camino
Importacion de datos a DB

Hola

Dado que ya tienes los datos en Excel me parece que es mas facil importarlos directamente del xls que del cvs ahi te envio un codigo que te puede ayudar
Código Delphi [-]
 procedure TFormMenu.Productos2Click(Sender: TObject);
 var
   j: Integer;
 begin
   try
     Excel := CreateOleObject('Excel.Application');
   except
     Excel.Quit;
     showmessage('No se pudo crear el Objecto Excel.');
     raise;
   end;
   if OpenDialogXls.Execute then Archivo:= OpenDialogXls.FileName
   else exit;
   Excel.Workbooks.Open(Archivo);
   j:= 2;
   try
     repeat
       with InsertarProductos do
       begin
         Close;
         Parameters.ParamByName('@codplu').Value:= Excel.Cells[j,1].Value;
         Parameters.ParamByName('@codtrasval').Value:= Excel.Cells[j,2].Value;
         Parameters.ParamByName('@codfabricante').Value:= Excel.Cells[j,3].Value;
         Parameters.ParamByName('@descripcionplu').Value:= Excel.Cells[j,4].Value;
         Parameters.ParamByName('@preciocosto').Value:= Excel.Cells[j,5].Value;
         Parameters.ParamByName('@precioventa').Value:= Excel.Cells[j,6].Value;
         Parameters.ParamByName('@um').Value:= Excel.Cells[j,7].Value;
         Parameters.ParamByName('@categoria').Value:= Excel.Cells[j,8].Value;
         Prepared:= True;
         ExecProc;
       end;
     inc(j);
     until Excel.Cells[j,2].Value = '';
     Excel.quit;
     ShowMessage(' El fichero de productos ha sido importado exitosamente');
   except
     ShowMessage(' !!!!! ATENCION !!!!! ' + chr(13) +
                     ' El fichero no pudo ser importado' + chr(13) +
                     ' Revise bien su estructura');
   end;
 end;
Donde Excel : Variant;

y en el uses incluir Excel97, ComObj

El ejemplo comienza en j:= 2 por que tengo encabezada la primera fila del documento.

Espero que te sea util

Saludos
Luis Garcia

_____________________________
La mejor manera de decir es hacer

Última edición por marcoszorrilla fecha: 14-04-2005 a las 22:09:23. Razón: Añadir etiquetas [Delphi]
Responder Con Cita