FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Exportar a Excel, sin abrir el archivo de resultados
Posts: 131
Joined: Tue Dec 26, 2006 04:50 PM
Exportar a Excel, sin abrir el archivo de resultados
Posted: Tue Sep 19, 2017 03:10 PM
Buenos d铆as Fivewineros, estoy exportando un DBF a Excel con el metodo antiguo para mi (Simplemente le cambio la extensi贸n al archivo de .DBF a .XLS y Excel lo abre sin problemas), pero tengo un comportamiento raro, agregu茅 varios campos (que hacen las veces de columnas en Excel), pero al exportar los datos de esas columnas aparecen vacias, las cabeceras si estan en mi archivo de resultados, pero los datos no (bastante raro, ya que antes de darle el comando "copy to" le puse un xbrowse para ver la informaci贸n y si aparecen los datos en las columnas que acabo de agregar.

Para tratar de darle la vuelta al asunto y de paso usar los metodos correctos hice un Xbrowse y us茅 la clausula ToExcel(), lo que necesito saber es como le hago para que no me abra el archivo de resultados, solo necesito que lo salve en una ubicaci贸n que ya tengo predeterminada.

Uso FW1604+Harbour+bcc7


Primero le pido al usuario un directorio donde salvar los resultados
Code (fw): Select all Collapse
cDirinfo=cGetdir("Selecciona el directorio para guardar la informaci贸n generada")


Despues genero un dialogo para mostrar los datos con un boton para exportarlo a excel (si hubiera una forma de ejecutar el "TOExcel()" SIN abrir un dialogo estar铆a mejor)
Code (fw): Select all Collapse
DEFINE DIALOG oDlg SIZE 800,600 PIXEL //FONT oFont

聽 聽@ 10, 10 XBROWSE oBrw ;
聽 聽 聽 聽 聽 聽 SIZE 120, 70 PIXEL ;
聽 聽 聽 聽 聽 聽 OF oDlg ;
聽 聽 聽 聽 聽 聽 AUTOCOLS ;
聽 聽 聽 聽 聽 聽 LINES
聽 聽 聽 聽 聽 聽 
聽 聽@ 250, 25 BTNBMP oBtn1 OF oDlg ;
聽 聽 SIZE 80, 15 PIXEL 2007 ;
聽 聽 NOBORDER ;
聽 聽 PROMPT " &AExcel() " ;
聽 聽 FILENAME cDirinfo ;
聽 聽 ACTION ( oBrw:ToExcel())
聽 聽 oBtn1:cToolTip = { "Enviar a Excel","Exportar", 1, CLR_BLACK, 14089979 }
聽 聽 oBtn1:SetColor( 0, )

聽 聽oBrw:CreateFromCode()

聽 聽ACTIVATE DIALOG oDlg CENTERED
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Exportar a Excel, sin abrir el archivo de resultados
Posted: Tue Sep 19, 2017 06:57 PM
No need to create xbrowse. Use FW_DbfToExcel()

Example:
Code (fw): Select all Collapse
USE CUSTOMER
oSheet := CUSTOMER->( FW_DbfToExcel())
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Exportar a Excel, sin abrir el archivo de resultados
Posted: Tue Sep 19, 2017 09:21 PM
This is working for me with Office 365.

Do not open the dbf file also.
Code (fw): Select all Collapse
function FW_CopyDBF2XL( cSourceDBF, cDestXLS )

聽 聽local oExcel, oBook, oSheet
聽 聽local aHead

聽 聽oExcel 聽 := ExcelObj()
聽 聽oBook 聽 聽:= oExcel:WorkBooks:Open( cSourceDBF )
聽 聽oBook:ActiveSheet:UsedRange:Columns:AutoFit()

聽 聽if cDestXLS == nil
聽 聽 聽 oExcel:Visible := .t.
聽 聽else
聽 聽 聽 cDestXLS 聽 聽:= TrueName( cDestXLS )
聽 聽 聽 oExcel:DisplayAlerts := .f.
聽 聽 聽 oBook:SaveAs( cDestXLS )
聽 聽 聽 oBook:Close()
聽 聽endif

return nil

Give sourcedbf with full path
Give the destination file name without extension.
Regards



G. N. Rao.

Hyderabad, India
Posts: 131
Joined: Tue Dec 26, 2006 04:50 PM
Re: Exportar a Excel, sin abrir el archivo de resultados
Posted: Wed Sep 20, 2017 09:29 PM

Thanks I'll try to do it this way (looks very promising).

Best regards

Posts: 131
Joined: Tue Dec 26, 2006 04:50 PM
Re: Exportar a Excel, sin abrir el archivo de resultados
Posted: Tue Oct 10, 2017 09:55 PM

Thanks a lot for your help, it works really great, I have a detail though, A user of mine tried to open a file when a file with the same name was already open, obviously an error poped up, I was worndering if there is a way to catch the error, in order to stop the program from crashing, I mean a way to let the user know the file is already open an give him the oportunity to close the opened file and retry saving the new one.

thanks in advance

Continue the discussion