EXCEL and FWH

EXCEL and FWH

Postby Ehab Samir Aziz » Sun Mar 19, 2006 6:14 am

Is there a Direct way of dealing with Excel and extract data from .dbf under some conditions to constitute Excel files ?
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby betoncu » Sun Mar 19, 2006 7:01 am

I Hope the code below helps.

Birol Betoncu



oExcel := CREATEOBJECT( "Excel.Application" )

oBook := oExcel:WorkBooks:Add()
oSheet := oBook:Worksheets(1)

nLine:=1
(cDBFILE)->(DBGOTOP())
DO WHILE !(cDBFILE)->(EOF())
oSheet:Cells( nLine, 1 ):Value = (cDBFILE)->Field1
oSheet:Cells( nLine, 2 ):Value = (cDBFILE)->Field2
nLine:=nLine+1
(cDBFILE)->(DBSKIP(1))
ENDDO

oExcel:Visible := .T.
User avatar
betoncu
 
Posts: 126
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

Postby Ehab Samir Aziz » Tue Mar 21, 2006 12:54 pm

There is no a class called createobject .
I tried that code with errors of non existence to createobject:
Code: Select all  Expand view

FUNCTION buildexcel()
*-------------------
local oExcel
local oBook
local oSheet
local nLine:=1


select 3
use mach

oExcel := CREATEOBJECT( "Excel.Application" )

oBook := oExcel:WorkBooks:Add()
oSheet:= oBook:Worksheets(1)

nLine:=1
3->(DBGOTOP())
DO WHILE !(3)->(EOF())
oSheet:Cells( nLine, 1 ):Value = (3)->mc_serial
oSheet:Cells( nLine, 2 ):Value = (3)->mc_name
nLine:=nLine+1
(3)->(DBSKIP(1))
ENDDO

oExcel:Visible := .T.

return nil
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Enrico Maria Giordano » Tue Mar 21, 2006 2:02 pm

Ehab Samir Aziz wrote:There is no a class called createobject .


You have to use xHarbour or link hbole.lib.

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

Postby Ehab Samir Aziz » Tue Mar 21, 2006 5:29 pm

Can you help me of code that helps me to Extract DBF fields values to Excel sheet ?
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Enrico Maria Giordano » Tue Mar 21, 2006 5:32 pm

Betoncu sample is fine.

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

Postby Ehab Samir Aziz » Tue Mar 21, 2006 9:16 pm

I reviewd the example of fw It works fine . Can any body send to my private mail the FWH program for Excel sheet builder ?
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Ehab Samir Aziz » Thu Mar 23, 2006 10:02 pm

You have to use xHarbour or link hbole.lib.


I did not find hbole.lib. Is its usage alternative of using harbour instead of xHarbour ?
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Antonio Linares » Fri Mar 24, 2006 7:51 am

Ehab,

Please change CreateObject() into CreateOleObject()
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Ehab Samir Aziz » Fri Mar 24, 2006 9:12 am

I got that error :

Error description: Error BASE/1004 Class: 'NUMERIC' has no exported method: WORKBOOKS

I am using harbour and rdd libraries in compilation (bldhrdd.bat)
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Antonio Linares » Fri Mar 24, 2006 9:37 am

Ehab,

Instead of doing:

oExcel:WorkBooks:Add()

try:

OleInvoke( OleGetProperty( oExcel, "WorkBooks" ), "Add" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Ehab Samir Aziz » Fri Mar 24, 2006 10:15 am

I tried this but the exe file closed by itself without any errors but where is the file created ?

Code: Select all  Expand view
FUNCTION buildexcel()
*-------------------

local oExcel
local oBook
local oSheet
local nLine:=1


select 3
use mach

oExcel := CREATEOLEOBJECT( "Excel.Application" )

oBook:=OleInvoke( OleGetProperty( oExcel, "WorkBooks" ), "Add" )
oSheet:=OleInvoke( OleGetProperty( oExcel, "WorkSheets(1)" ))


nLine:=1
3->(DBGOTOP())
DO WHILE !(3)->(EOF())
oSheet:Cells( nLine, 1 ):Value = (3)->mc_serial
oSheet:Cells( nLine, 2 ):Value = (3)->mc_name
nLine:=nLine+1
(3)->(DBSKIP(1))
ENDDO

oExcel:Visible := .T.

return nil
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Antonio Linares » Fri Mar 24, 2006 12:13 pm

Ehab,

This is the right code:
Code: Select all  Expand view
FUNCTION buildexcel()

   local oExcel , oBook, oSheet
   local nLine :=1

   oExcel = CREATEOLEOBJECT( "Excel.Application" )

   oBook = OleInvoke( OleGetProperty( oExcel, "WorkBooks" ), "Add" )
   oSheet = OleGetProperty( oBook, "WorkSheets", 1 )

   OleSetProperty( OleGetProperty( oSheet, "Cells", nLine, 1 ), "Value", "test" )

   OleSetProperty( oExcel, "Visible", .t. )

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Ehab Samir Aziz » Fri Mar 24, 2006 12:24 pm

ok. That what I finished to . The Excel sheet opened but no data written to it .

Code: Select all  Expand view
FUNCTION ADDNMRNG_WORK()
//----------------------
    LOCAL cPath := "E:\programs\clipper\fwh\sitex\OLE.XLS"
    LOCAL oExcel
    LOCAL oBook
    LOCAL osheet
    LOCAL nline:=0





    oExcel := CreateOLEObject("Excel.Application")

    OLESetProperty(oExcel,"Visible",TRUE)

    oBook:=OleInvoke( OleGetProperty( oExcel, "WorkBooks" ), "Add" )

    oSheet:=OleInvoke( OleGetProperty( oBook, "Worksheets(1)" ))






    OLEInvoke(oBook,"Open",cPath)





select 3
use mach
nLine:=1
3->(DBGOTOP())
DO WHILE !(3)->(EOF())
oSheet:Cells( nLine, 1 ):Value = (3)->mc_serial
oSheet:Cells( nLine, 2 ):Value = (3)->mc_name
nLine:=nLine+1
(3)->(DBSKIP(1))
ENDDO


    OLEInvoke(oExcel,"Quit")
RETURN NIL
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Antonio Linares » Fri Mar 24, 2006 12:27 pm

Ehab,

Please review and test the sample that I have provided to you.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 69 guests