Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Conexión con bases de datos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Conexión con bases de datos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 18-12-2006
ronimaxh ronimaxh is offline
Miembro
 
Registrado: jun 2003
Ubicación: Rep. Dominicana
Posts: 307
Poder: 22
ronimaxh Va por buen camino
importar de excel a sql 2000

Hola amigos como puedo importar archivos de excel usando delphi 7 a sql server 2000, lo que quiero es que la aplicacion realice importacion si tengo varios archivos de excel como puedo abrirlo y recorrerlo y después importarlo a la vez a sql. Preferiblemente usando OpenDialog, desde ya gracias por cualquier ayuda...
__________________
ronimaxh
Rep. Dominicana
Responder Con Cita
  #2  
Antiguo 19-12-2006
lgarcia lgarcia is offline
Miembro
 
Registrado: jul 2004
Posts: 481
Poder: 20
lgarcia Va por buen camino
Importar a SQL

Hola:

Ahi te envio el siguiente codigo que lo he ido conformando con cosas del club

Código:
var
  x: Integer;
  Excel : Variant;
  Archivo: String;
procedure TFormEntradaFecha.OKBtnClick(Sender: TObject);
var
  j: Integer;
  hoja: Variant;
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;
  NombreFichero:= ExtractFileName(Archivo);
  Excel.Workbooks.Open(Archivo);
  j:= MostrarTerritoriounidades.Value + 8;
  try
    with InsTabla1 do
    begin
      Hoja:= ExcelApp.Worksheets.Item['tabla1'];
      Hoja.Activate;
      Close;
      Parameters.ParamByName('@territorio').Value:= cbTerritorio.KeyValue;
      Parameters.ParamByName('@fecha').Value:= Int(DTP1.Date);
      Parameters.ParamByName('@altas').Value:= Excel.Cells[j,2].Value;
      Parameters.ParamByName('@bajas').Value:= Excel.Cells[j,3].Value;
      Parameters.ParamByName('@movimientos').Value:= Excel.Cells[j,4].Value;
      Parameters.ParamByName('@dirigtotal').Value:= Excel.Cells[j,5].Value;
      Parameters.ParamByName('@dirigmuj').Value:= Excel.Cells[j,6].Value;
      Parameters.ParamByName('@tectotal').Value:= Excel.Cells[j,7].Value;
      Parameters.ParamByName('@tecmuj').Value:= Excel.Cells[j,8].Value;;
      Parameters.ParamByName('@admontotal').Value:= Excel.Cells[j,9].Value;
      Parameters.ParamByName('@admonmuj').Value:= Excel.Cells[j,10].Value;
      Parameters.ParamByName('@servtotal').Value:= Excel.Cells[j,11].Value;;
      Parameters.ParamByName('@servmuj').Value:= Excel.Cells[j,12].Value;;
      Parameters.ParamByName('@obtotal').Value:= Excel.Cells[j,13].Value;;
      Parameters.ParamByName('@obmuj').Value:= Excel.Cells[j,14].Value;;
      Parameters.ParamByName('@militares').Value:= Excel.Cells[j,15].Value;;
      Parameters.ParamByName('@promedio').Value:= Excel.Cells[j,16].Value;;
      Parameters.ParamByName('@promacum').Value:= Excel.Cells[j,17].Value;;
      Parameters.ParamByName('@indirectos').Value:= Excel.Cells[j,18].Value;;
      Parameters.ParamByName('@porciento').Value:= Excel.Cells[j,19].Value;;
      Prepared:= True;
      ExecProc;
    end;
    with InsTabla2 do
    begin
      Hoja:= ExcelApp.Worksheets.Item['tabla2'];
      Hoja.Activate;
      Close;
      Parameters.ParamByName('@territorio').Value:= cbTerritorio.KeyValue;
      Parameters.ParamByName('@fecha').Value:= Int(DTP1.Date);
      Parameters.ParamByName('@cajeroa').Value:= Excel.Cells[j,2].Value;
      Parameters.ParamByName('@cajerob').Value:= Excel.Cells[j,3].Value;
      Parameters.ParamByName('@cajeror').Value:= Excel.Cells[j,4].Value;
      Parameters.ParamByName('@veedor').Value:= Excel.Cells[j,5].Value;
      Parameters.ParamByName('@boveda').Value:= Excel.Cells[j,6].Value;
      Parameters.ParamByName('@jefetrip').Value:= Excel.Cells[j,7].Value;
      Parameters.ParamByName('@choferesc').Value:= Excel.Cells[j,8].Value;;
      Parameters.ParamByName('@asv').Value:= Excel.Cells[j,9].Value;
      Parameters.ParamByName('@jefeinst').Value:= Excel.Cells[j,10].Value;
      Parameters.ParamByName('@jefegrupo').Value:= Excel.Cells[j,11].Value;;
      Parameters.ParamByName('@asp').Value:= Excel.Cells[j,12].Value;;
      Parameters.ParamByName('@oficialguardia').Value:= Excel.Cells[j,13].Value;;
      Parameters.ParamByName('@cctv').Value:= Excel.Cells[j,14].Value;;
      Parameters.ParamByName('@jefemens').Value:= Excel.Cells[j,15].Value;;
      Parameters.ParamByName('@chofermens').Value:= Excel.Cells[j,16].Value;;
      Parameters.ParamByName('@jefepiso').Value:= Excel.Cells[j,17].Value;;
      Parameters.ParamByName('@cajerov').Value:= Excel.Cells[j,18].Value;;
      Prepared:= True;
      ExecProc;
    end;
   
    Excel.quit;
    ShowMessage('El fichero ha sido importado exitosamente');
  except
    ShowMessage('      !!!!! ATENCION !!!!! ' + chr(13) +
                'El fichero no pudo ser importado' + chr(13) +
                'Revise el fichero de importación');
  end;
end;
En el uses de la implementacion deben agregar estas dos units Excel97, ComObj
Responder Con Cita
  #3  
Antiguo 19-12-2006
ronimaxh ronimaxh is offline
Miembro
 
Registrado: jun 2003
Ubicación: Rep. Dominicana
Posts: 307
Poder: 22
ronimaxh Va por buen camino
gracias por responder amigo, aqui va la pregunta,
ostrarTerritoriounidades.Value 'que es esto no lo entiendo'
__________________
ronimaxh
Rep. Dominicana
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Importar Excel a RTF CARSOFT_AR Varios 0 24-08-2005 19:59:18
importar de excel a BD jmlifi Varios 2 09-08-2005 11:47:18
Importar Campos De Excel jadelphi Varios 2 13-04-2005 20:02:54
Problema al actualizar Excel 2000 a Excel XP victork_py Servers 1 06-08-2004 19:20:41
importar de excel joanajj Servers 3 04-08-2004 12:35:02


La franja horaria es GMT +2. Ahora son las 16:34:42.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi