FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Excel Files
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Excel Files
Posted: Mon Apr 23, 2007 10:55 PM

Hi forum,

Can we read and save as DBF an excel (XLS) file, using only xHarbour + FWH, with not microsoft excel installed in the computer?

Regards,

George

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Excel Files
Posted: Tue Apr 24, 2007 07:12 AM
Try something like this:

FUNCTION MAIN()

    LOCAL oCn := CREATEOBJECT( "ADODB.Connection" )

    oCn:Open( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\xharbour\mytest.xls;Extended Properties='Excel 8.0'" )

    oCn:Execute( "SELECT * INTO [DBASE III; Database=c:\xharbour].mytest FROM [MySheet$]" )

    oCn:Close()

    RETURN NIL


Please note that the $ sign after the sheet name is required.

EMG
Posts: 840
Joined: Thu Oct 13, 2005 07:05 PM
Excel Files
Posted: Tue Apr 24, 2007 04:27 PM

You can also try FileXLS class, it writes direct XLS files, no need to have anything installed.

Saludos

R.F.
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Excel Files
Posted: Tue Apr 24, 2007 05:07 PM

Ok, but George needs to read from an XLS and write to a DBF, if I understood correctly.

EMG

Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Excel Files
Posted: Sat Apr 28, 2007 01:30 PM

Enrico, Rene,

That is correct. I have to read an XLS file, created by another program, and save it as DBF in order to do some process with my xHarbour + FWH software.
By now I am using TEXCEL.PRG class. It is working fine, but as you know wee need to have Microsoft Excel installed.

BTW a do you know how to, when saving the XLS file as DBF, to have a field (in the generated DBF) as logical? Now I can have numerical and chars fields automatically created from the XLS, but not logical field.

Regards,

George

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Excel Files
Posted: Sat Apr 28, 2007 06:47 PM

George,

>BTW a do you know how to, when saving the XLS file as DBF, to have a field (in the generated DBF) as logical? Now I can have numerical and chars fields automatically created from the XLS, but not logical field.

This is a round about way, but you could process the first DBF as a temp file, and change all the data in the field you want to be logical as you copy the data to a new file.

Or, another idea just came to me, you can subclass TDatabase and modify the load method to convert the data each time a record is read. This way there is another (mock) field that is logical. Let me know if you would like an example.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Excel Files
Posted: Sat Apr 28, 2007 11:50 PM

James,

I am trying to avoid modify the DBF. I would prefer using TEXCEL class to create a logical type column in the XLS file, before saving as DBF; I don't know if that is possible.

I am glad to see you example.

Regards,

George

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Excel Files
Posted: Sun Apr 29, 2007 07:07 PM

George,

>I am trying to avoid modify the DBF. I would prefer using TEXCEL class to create a logical type column in the XLS file, before saving as DBF; I don't know if that is possible.

>I am glad to see you example.

First create a subclass of TDatabase. Lets assume your fieldname is "ACTIVE" (the one you want to be a logical). We create a new fake field ISACTIVE. I don't know what your field contains, but here lets assume it contains Y or N.

class TMyData from TDatabase
data isactive
method load
endclass

method load class TDatabase
super:load()
// Convert the real field to a logical
::isactive:= if(::ACTIVE="Y",.t.,.f.)
return self

Now to use it all you do is this:

use mydata
oMyData:= TMyData():new()

msgInfo( oMyData:isactive ) // returns .t. or .f.

Simple.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Excel Files
Posted: Sun Apr 29, 2007 07:16 PM

Anyone,

Where can I get a copy of the TExcel class?

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 990
Joined: Wed Oct 19, 2005 02:17 PM
Excel Files
Posted: Sun Apr 29, 2007 07:32 PM

James,

following the link:

http://fivetechsoft.com/forums/viewtopic.php?t=2765

Best regards,

Felix

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Excel Files
Posted: Sun Apr 29, 2007 07:35 PM

Felix,

Thanks but the link to TXLS is now dead.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Excel Files
Posted: Sun Apr 29, 2007 07:44 PM

OK, I found the TXLS.ZIP file on my own disk. I was looking for TEXCEL.ZIP before.

Now I am confused. George, didn't you say that you were using TEXCEL to read an Excel file? The version I have only writes to Excel files.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 14
Joined: Sun Apr 29, 2007 02:04 PM
CreateXLS
Posted: Sun Apr 29, 2007 08:30 PM

I have code in VB for creating XLS file direct with FCREATE() and FWRITE()
If you interesting I can send this file for conversion to xHarbour

TO BE or NOT TO BE

Srdjan Dragojlovic
www.digicad.biz
Posts: 729
Joined: Tue Oct 18, 2005 06:49 PM
Excel Files
Posted: Sun Apr 29, 2007 09:02 PM

James

> Where can I get a copy of the TExcel class?
Sent to your email

Digicad,

Please send the VB code to georgeabinader@msn.com

Regards,

George

Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Clase TXLS
Posted: Mon Apr 30, 2007 03:42 AM
Saludos/Regards,

José Murugosa

"Los errores en programación, siempre están entre la silla, el teclado y la IA!!"