Ejemplo de Excel a DBF

HMG en Español

Moderator: Rathinagiri

User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Ejemplo de Excel a DBF

Post 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.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
Anand
Posts: 595
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF

Re: Ejemplo de Excel a DBF

Post 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
Regards,

Anand

Image
jparada
Posts: 430
Joined: Fri Jan 23, 2009 5:18 pm

Re: Ejemplo de Excel a DBF

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