Page 2 of 2

Re: Ejemplo de Excel a DBF

Posted: Fri Oct 11, 2019 1:32 pm
by andyglezl
Quizá de esta forma...
*---------------------------
Maybe this way ...


Function Excel2DBF( cExcelName )
*------------------------------------------------------------------------*
LOCAL oExcel := nil
LOCAL oActive := nil

oExcel := TOleAuto():New( "Excel.Application" )
oExcel:WorkBooks:Open( cExcelName )
oActive := oExcel:ActiveSheet()

oExcel:DisplayAlerts := .F. // Doesn't display Excel alerts
oExcel:Visible := .F. // Do not show the excel file on screen

oExcel:ActiveWorkbook:SaveAS( cExcelName + ".CSV", 6 )
oExcel:Application:Quit()

RELEASE oActive
RELEASE oExcel

USE MyFileDBF
APPEND FROM cExcelName + ".CSV"

Msginfo("Finished!!!","Done!")

return
APPEND FROM <xcFile>
[FIELDS <idField list>]
[<scope>] [WHILE <lCondition>] [FOR <lCondition>]
[SDF | DELIMITED [WITH BLANK | <xcDelimiter>] |
[VIA <xcDriver>]]

Description
APPEND FROM adds records to the current database file from an ASCII text file or another database file. Only fields with the same names and types are APPENDed. Fields with the same name from both the current database file and xcFile must be the same data type. If they are not, a runtime error occurs when the APPEND FROM command is invoked.

Any date information in xcFile must be in the format yyyymmdd to be properly APPENDed.

Re: Ejemplo de Excel a DBF

Posted: Sat Oct 12, 2019 10:09 am
by Anand
"Any date information in xcFile must be in the format yyyymmdd to be properly APPENDed. "
This condition will not be fulfilled by Excel exporting to CSV, IMHO.

Regards,

Anand

Re: Ejemplo de Excel a DBF

Posted: Sat Oct 12, 2019 1:59 pm
by jparada
Hola,
Gracias a todos por sus respuestas.

Lo que estaba buscando es resolver el problema que el archivo de Excel queda abierto/bloqueado, al parecer con:

Code: Select all

oExcel:WorkBooks:Close() // CIERRA LIBRO ACTIVO
oExcel:Quit() // CIERRA EXCEL
Se resuelve el problema, he realizado varias pruebas y así no ha quedado bloqueado el archivo.

Gracias al usuario AUGE_OHR por el tip, en este caso estoy leyendo un archivo de Excel para actualizar algunos datos de una tabla, base de datos MS-SQL Server.

Saludos,
Javier