Excel Files

Excel Files

Postby George » 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
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Re: Excel Files

Postby Enrico Maria Giordano » Tue Apr 24, 2007 7:12 am

Try something like this:

Code: Select all  Expand view
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
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby R.F. » Tue Apr 24, 2007 4:27 pm

You can also try FileXLS class, it writes direct XLS files, no need to have anything installed.
Saludos
R.F.
R.F.
 
Posts: 840
Joined: Thu Oct 13, 2005 7:05 pm

Postby Enrico Maria Giordano » Tue Apr 24, 2007 5:07 pm

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

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby George » Sat Apr 28, 2007 1: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
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Postby James Bott » Sat Apr 28, 2007 6: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby George » 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
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Postby James Bott » Sun Apr 29, 2007 7: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Sun Apr 29, 2007 7:16 pm

Anyone,

Where can I get a copy of the TExcel class?

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Baxajaun » Sun Apr 29, 2007 7:32 pm

James,

following the link:

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

Best regards,

Felix
User avatar
Baxajaun
 
Posts: 968
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Postby James Bott » Sun Apr 29, 2007 7:35 pm

Felix,

Thanks but the link to TXLS is now dead.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby James Bott » Sun Apr 29, 2007 7: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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

CreateXLS

Postby digicad » Sun Apr 29, 2007 8: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
User avatar
digicad
 
Posts: 14
Joined: Sun Apr 29, 2007 2:04 pm
Location: Serbia

Postby George » Sun Apr 29, 2007 9: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
George
 
Posts: 725
Joined: Tue Oct 18, 2005 6:49 pm

Clase TXLS

Postby jose_murugosa » Mon Apr 30, 2007 3:42 am

Saludos/Regards,
José Murugosa
"Los errores en programación, siempre están entre la silla y el teclado y la IA!!"
User avatar
jose_murugosa
 
Posts: 1180
Joined: Mon Feb 06, 2006 4:28 pm
Location: Uruguay

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 39 guests