Ejemplo de Excel a DBF

HMG en Español

Moderator: Rathinagiri

User avatar
andyglezl
Posts: 1191
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 37 times
Been thanked: 85 times
Contact:

Re: Ejemplo de Excel a DBF

Post by andyglezl » Fri Oct 11, 2019 1:32 pm

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: 428
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 127 times
Been thanked: 60 times

Post by Anand » Sat Oct 12, 2019 10:09 am

"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
Image

jparada
Posts: 273
Joined: Fri Jan 23, 2009 5:18 pm
Been thanked: 4 times

Post by jparada » Sat Oct 12, 2019 1:59 pm

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