Extraer Informacion de una Planilla de Excel

Post Reply
dobfivewin
Posts: 325
Joined: Sun Feb 03, 2008 11:04 pm
Location: Argetnina

Extraer Informacion de una Planilla de Excel

Post 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.
User avatar
Lautaro
Posts: 322
Joined: Fri Oct 07, 2005 2:44 pm
Location: Osorno, Chile
Contact:

Re: Extraer Informacion de una Planilla de Excel

Post 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
User avatar
ADBLANCO
Posts: 299
Joined: Mon Oct 22, 2007 3:03 pm
Location: Valencia - Venezuela

Re: Extraer Informacion de una Planilla de Excel

Post 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
 
Saludos

Angel, Valencia, Venezuela

xH .997 - FW 7.9 - BCC55 - WorkShop - MySql
User avatar
ADBLANCO
Posts: 299
Joined: Mon Oct 22, 2007 3:03 pm
Location: Valencia - Venezuela

Re: Extraer Informacion de una Planilla de Excel

Post 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
 
Saludos

Angel, Valencia, Venezuela

xH .997 - FW 7.9 - BCC55 - WorkShop - MySql
dobfivewin
Posts: 325
Joined: Sun Feb 03, 2008 11:04 pm
Location: Argetnina

Re: Extraer Informacion de una Planilla de Excel

Post by dobfivewin »

Amigos

MUCHAS GRACIAS

Lo pruebo y les Aviso...

1000000 de gracias

David
Post Reply