Dbf To Excel(Excel Functions)

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
vagblad
Posts: 160
Joined: Tue Jun 18, 2013 12:18 pm
DBs Used: MySQL,DBF
Location: Thessaloniki, Greece

Dbf To Excel(Excel Functions)

Post by vagblad »

Hello all,

Recently Nikos(quartz56) and me had to export some of our dbf files to Excel and PDF format. Also we wanted the files to be ready for printing with all columns fitted in one page and landscape orienttaion. We made a small function who does the job and we thought to share with the rest in case it helps someone.
The thing to notice is the ability to export directly to PDF format through Excel Vba and some nice VBA methods.

Best Regards

P.S. :Rathi you can move it under the Samples forum if you want, i am sorry i post it by mistake in the wrong area.Thanks!
-------------------------------------------------------------------------------------------------------------------------------------------
Hola a todos,

Recientemente Nikos ( quartz56 ) y me tenían que exportar algunos de nuestros archivos de DBF a formato PDF . Hicimos una pequeña función que hace el trabajo y pensamos que compartir con el resto en caso de que ayuda a alguien .
Lo que hay que notar es la capacidad de exportar directamente a formato PDF a través de Excel VBA y algunos métodos de VBA agradables .

Atentamente
Attachments
DbfExcel.rar
(1.23 MiB) Downloaded 745 times
Last edited by vagblad on Fri Jul 15, 2016 7:57 am, edited 1 time in total.
Vagelis Prodromidis
Email: vagblad@gmail.com, Skype: vagblad
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Dbf To Excel(Excel Functions)

Post by mustafa »

Hola amigo vagblad
He probado tu sample y me da este ERROR
*--------------------------------------------------*
Date:07/14/16 Time: 19:28:59
Error WINOLE/1007 (0x80070057): EXPORTASFIXEDFORMAT (DOS Error -2147352567)
Called from TOLEAUTO:EXPORTASFIXEDFORMAT(0)
Called from DBFTOEXCEL(79)
Called from (b)MAIN(59)
Called from _DOCONTROLEVENTPROCEDURE(6033)
Called from EVENTS(1754)
Called from DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(5696)
Called from DOMETHOD(8914)
Called from MAIN(8)
*---------------------------------------------------*
Yo hace tiempo renombro los ficheros DBF a XLS y parece
que funciona, te mando como lo hago.
Basado en la estructura de tu sample.
Saludos


Hello friend vagblad
I tried your sample and I get this ERROR
* ------------------------------------------------- - *
Date: 07/14/16 Time: 19:28:59
Error WINOLE / 1007 (0x80070057): ExportAsFixedFormat (DOS Error -2147352567)
Called from TOLEAUTO: ExportAsFixedFormat (0)
Called from DBFTOEXCEL (79)
Called from (b) MAIN (59)
Called from _DOCONTROLEVENTPROCEDURE (6033)
Called from Events (1754)
Called from DOMESSAGELOOP (0)
Called from _ACTIVATEWINDOW (5696)
Called from DOMETHOD (8914)
Called from MAIN (8)
* ------------------------------------------------- - *
I long ago renamed the DBF files to XLS and seems
that works, I command as I do.
Based on the structure of your sample.
regards

Mustafa
Attachments
Sample_Dbf_Excel_New.zip
(57.83 KiB) Downloaded 599 times
Last edited by mustafa on Sat Jul 16, 2016 1:48 pm, edited 1 time in total.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Dbf To Excel(Excel Functions)

Post by serge_girard »

Thanks Vagelis and Mustafa for sharing!

Serge
There's nothing you can do that can't be done...
User avatar
vagblad
Posts: 160
Joined: Tue Jun 18, 2013 12:18 pm
DBs Used: MySQL,DBF
Location: Thessaloniki, Greece

Re: Dbf To Excel(Excel Functions)

Post by vagblad »

mustafa wrote:Hola amigo vagblad
He probado tu sample y me da este ERROR
*--------------------------------------------------*
Hello friend vagblad
I tried your sample and I get this ERROR
Hello Mustafa,

I think the error is because of the filename. In the textbox which shows the Excel FileName, don't add the extension (.xls or .xlsx) because the function adds the .xls by itself.

Thanks a lot for your sample also!

P.S.:To make my first post more clear, we wanted a function to give us an excel and a pdf file at the same time fast. Also we wanted the final result to be formatted ready for printing with all columns fitted in one page and with landscape orientation. I know we have examples to get pdf from dbf and excel from dbf. I just thought it was nice to see some excel vba methods in action :) . I will update the original post to be more clear.
--------------------------------------------------------------------------------------------------------------------------------------------------
Hola Mustafa ,

Creo que el error es debido al nombre de archivo. En el cuadro de texto que muestra el Nombre de archivo de Excel , no añada la extensión ( .xls o .xlsx ) debido a que la función añade la .xls por sí mismo .

mucho por su ejemplo también gracias !

P.S.:To hacer mi primer mensaje más claro , queríamos una función para darnos una un archivo PDF a la vez rápido y Excel . También queríamos que el resultado final sea el formato listo para imprimir con todas las columnas instaladas en una página y con orientación horizontal . Sé que tenemos ejemplos para obtener el pdf de DBF y Excel desde DBF . Sólo pensé que era agradable para ver algunos sobresalen métodos de VBA en la acción :) . Voy a actualizar el post original para ser más clara .
Vagelis Prodromidis
Email: vagblad@gmail.com, Skype: vagblad
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Dbf To Excel(Excel Functions)

Post by mustafa »

Hola amigo vagblad
Sobre tu Sample me sigue dando el mismo Error que te mencioné
yo no pongo ninguna extensión Xls , después de elegir Fichero DBF
e indicar que convierta el nuevo Fichero Excel xls , OK
el Error se produce cuando intenta convertir a PDF he anulado la línea
de código:

----> * oExcel:ActiveWorkbook:ExportAsFixedFormat(0,cExcelName + ".PDF") //Export the excel file as PDF

y el Sample funciona OK , por lo tanto creo que habría que revisar esta línea
de código que produce el Error
saludos

*------------------------------------- Google -----------------------------------------------------*
Hello friend vagblad
About your Sample still gives me the same Error I mentioned
I do not put any extension xls, after choosing File DBF
and indicate that converts the new Excel xls file, OK
The Error occurs when you try to convert PDF've canceled the line
code:

----> * OExcel: ActiveWorkbook: ExportAsFixedFormat (0, cExcelName + ".PDF") // Export the file as PDF excel

and Sample works OK, so I think we should check this line
code that produces the Error
greeting
Mustafa
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Dbf To Excel(Excel Functions)

Post by mustafa »

Hola vagblad:
Ya descubrí porque tira Error es porque mi Excel
no tenía instado el Plugin de Microsoft
para salvar a Fichero Pdf -> SaveAsPDFandXPS.exe
el que no lo tenga instalado hay que bajarlo de
https://www.microsoft.com/es-es/downloa ... .aspx?id=7
una vez instalado el Plugin funciona OK el Sample.

Ver dibujo mirar si teneis instalado Plugin cuando indicais
Guardar como ... Tiene que aparecer a la derecha PDF

Saludos

*---------------------------Google ----------------*
Hello vagblad:
And I discovered that strip error is because my Excel
it had urged the plugin Microsoft
Pdf file to save -> SaveAsPDFandXPS.exe
which does not have it installed you have to download it from
https://www.microsoft.com/es-es/downloa ... .aspx?id=7
once the works OK the Sample Plugin installed.

See drawing look if you have installed Plugin when indicáis
Save As ... you have to appear to the right PDF

regards

Mustafa
Attachments
Imagen.jpg
Imagen.jpg (57.75 KiB) Viewed 8182 times
Tiger
Posts: 70
Joined: Mon Aug 31, 2015 11:28 am
Location: Taipei

Re: Dbf To Excel(Excel Functions)

Post by Tiger »

Hi Vagelis,

Thanks for the sharing.

I am using the office 2007 and I need to add following codes to get it work.

sele 0
use &cDbfFile new


nRecNo := LastRec() +1
aStructure := DBStruct()
nFields := len(aStructure)

use
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Dbf To Excel(Excel Functions)

Post by SALINETAS24 »

Hola, una ayuda.
En mi programa MAIN tengo estos SET's iniciales
SET LANGUAGE TO SPANISH
REQUEST HB_LANG_ESWIN
HB_LANGSELECT( "ESWIN" )
SET CODEPAGE TO UNICODE
SET DATE FRENCH
SET CENTURY ON
SET EXCLUSIVE OFF

y otro PRG convierto un DBF a EXCEL pero las fechas me aparecen mal, unas salen con formato 04/02/2018 y en la misma columna otras con formato 20180414. El fichero lo abro con DBU y esta bien, y su definición correcta "D".
¿saben a que se debe ese cambio..?
Gracias
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Dbf To Excel(Excel Functions)

Post by mustafa »

Añade
SET CENTURY ON
SET DATE FORMAT TO 'dd/mm/yyyy'

Haber que pasa
Chao
Mustafa
User avatar
SALINETAS24
Posts: 667
Joined: Tue Feb 27, 2018 3:06 am
DBs Used: DBF
Contact:

Re: Dbf To Excel(Excel Functions)

Post by SALINETAS24 »

Hola Mustafa lo he probado y ya se lo que me pasa, pero no se la solución.

El fichero DBF original tiene 6 campos de los cuales 2 son fecha, si lo abro con el DBU veo "04/28/18" y "04/01/18", oase "mes/dia/año" que es así como se me graba en el DBF.
Seguidamente abro el fichero que crea tu rutina al mediante la función "DBCREATE()" y obtengo el mismo resultado ,"04/25/18" y "04/01/18"... pero que ocurre cuando abro el EXCEL.
Me los ha convertido y me ha cambiado el orden, el día pasa a ser el mes y el mes el dia, por eso algunos los presenta en el formato fecha cuando el dato es correcto y otros como cadena cuando interpreta que el numero MES es mayor de 12. Estas fechas del ejemplo son visualizadas así "20180425" y "04/01/2018".
Y si ejecuto tu programa me ocurre exactamente lo mismo.

Para salir de dudas lo he ejecutado sobre la base que crea el programa samples\aplications\contactos, he dado de alta un registro con la fecha de nacimiento "18/01/1970" y el resultado ha sido el mismo, cambia el mes por el día.

Muuuuyy raro...

Gracias por tu tiempo y paciencia.
Como dijo el gran pensador Hommer Simpson..., - En este mundo solo hay 3 tipos de personas, los que saben contar y los que no. :shock:
Post Reply