Page 1 of 1

Extraer Informacion de una Planilla de Excel

Posted: Fri Sep 11, 2009 3:07 pm
by dobfivewin
Estimados

Que me aconsejan usar para extraer informacion de una planilla de Excel.

La idea es leer la planilla y pasarla a una base de datos.

Gracias

David
Argertina.

Re: Extraer Informacion de una Planilla de Excel

Posted: Fri Sep 11, 2009 3:34 pm
by Lautaro
David,

Desde mi experiencia, si te animas con ole, es la mejor opcion, y la otra es "Guardar como" y si usas office 2007 solo te sirve txt ya que no puedes crear dbfs con office 2007 , si es una version anterior puedes guardarlo como dbf.

atte.,

Lautaro Moreira
Osorno
Chile

Re: Extraer Informacion de una Planilla de Excel

Posted: Fri Sep 11, 2009 3:36 pm
by ADBLANCO
Te refieres a algo como esto???
:lol:

Code: Select all

*******************************************************************************************************
STATIC PROCEDURE LEER()                                // lee una tabla excell y crea un archivo dbf
*******************************************************************************************************
   LOCAL oExcel, oHoja, nRows, nCols
   LOCAL aCampos:={}, nRow, nCol
   oExcel := TOleAuto():New( "Excel.Application" )
   oExcel:WorkBooks:Open(cFilePath(GetModuleFileName(GetInstance()))+"Prueba.xls")
   oHoja := oExcel:Get( "ActiveSheet" )
   nRows := oHoja:UsedRange:Rows:Count()
   nCols := oHoja:UsedRange:Columns:Count()
   FOR nCol := 1 TO nCols
      IF ValType( oHoja:Cells( 2, nCol ):Value ) = "C"
         AADD( aCampos, { oHoja:Cells( 1, nCol ):Value, "C", 80, 0 } )
      ELSEIF ValType( oHoja:Cells( 2, nCol ):Value ) = "N"
         AADD( aCampos, { oHoja:Cells( 1, nCol ):Value, "N", 15, 4 } )
      ELSEIF ValType( oHoja:Cells( 2, nCol ):Value ) = "L"
         AADD( aCampos, { oHoja:Cells( 1, nCol ):Value, "L", 1, 0 } )
      ELSEIF ValType( oHoja:Cells( 2, nCol ):Value ) = "D"
         AADD( aCampos, { oHoja:Cells( 1, nCol ):Value, "D", 8, 0 } )
      ENDIF
   NEXT
   DBCREATE( "PRUEBA", aCampos )
   USE "PRUEBA" NEW
   FOR nRow := 2 TO nRows
      APPEND BLANK
      FOR nCol := 1 TO nCols
         FIELDPUT( nCol, oHoja:Cells( nRow, nCol ):Value )
      NEXT
   NEXT
   CLOSE DATABASES
   oExcel:Quit()
   *oHoja:End()
   *oExcel:End()
   MsgInfo( "Se ha creado el fichero PRUEBA.DBF" )
RETURN
 

Re: Extraer Informacion de una Planilla de Excel

Posted: Fri Sep 11, 2009 3:42 pm
by ADBLANCO
Y aquí está el caso contrario

:roll:

Code: Select all

*******************************************************************************************************
STATIC PROCEDURE ENVIAR()                             // lee un dbf y genera una tabla excell
*******************************************************************************************************
   LOCAL oExcel, oHoja
   LOCAL nRow := 1, nCol
   oExcel := TOleAuto():New( "Excel.Application" )
   oExcel :WorkBooks:Add()
   oHoja  := oExcel:Get( "ActiveSheet" )
   USE "PRUEBA" NEW
   FOR nCol := 1 TO FCOUNT()
      oHoja:Cells( nRow, nCol ):Value := FieldName( nCol )
   NEXT
   DO WHILE .NOT. EOF()
      nRow++
      FOR nCol := 1 TO FCOUNT()
         oHoja:Cells( nRow, nCol ):Value := FieldGet( nCol )
      NEXT
      SKIP
   ENDDO
   FOR nCol := 1 TO FCOUNT()
      oHoja:Columns( nCol ):AutoFit()
   NEXT
   CLOSE DATABASES
   oExcel:Visible := .t.
RETURN
 

Re: Extraer Informacion de una Planilla de Excel

Posted: Fri Sep 11, 2009 9:18 pm
by dobfivewin
Amigos

MUCHAS GRACIAS

Lo pruebo y les Aviso...

1000000 de gracias

David