Page 1 of 2

EXCEL and FWH

Posted: Sun Mar 19, 2006 6:14 am
by Ehab Samir Aziz
Is there a Direct way of dealing with Excel and extract data from .dbf under some conditions to constitute Excel files ?

Posted: Sun Mar 19, 2006 7:01 am
by betoncu
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.

Posted: Tue Mar 21, 2006 12:54 pm
by Ehab Samir Aziz
There is no a class called createobject .
I tried that code with errors of non existence to createobject:

Code: Select all


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

Posted: Tue Mar 21, 2006 2:02 pm
by Enrico Maria Giordano
Ehab Samir Aziz wrote:There is no a class called createobject .
You have to use xHarbour or link hbole.lib.

EMG

Posted: Tue Mar 21, 2006 5:29 pm
by Ehab Samir Aziz
Can you help me of code that helps me to Extract DBF fields values to Excel sheet ?

Posted: Tue Mar 21, 2006 5:32 pm
by Enrico Maria Giordano
Betoncu sample is fine.

EMG

Posted: Tue Mar 21, 2006 9:16 pm
by Ehab Samir Aziz
I reviewd the example of fw It works fine . Can any body send to my private mail the FWH program for Excel sheet builder ?

Posted: Thu Mar 23, 2006 10:02 pm
by Ehab Samir Aziz
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 ?

Posted: Fri Mar 24, 2006 7:51 am
by Antonio Linares
Ehab,

Please change CreateObject() into CreateOleObject()

Posted: Fri Mar 24, 2006 9:12 am
by Ehab Samir Aziz
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)

Posted: Fri Mar 24, 2006 9:37 am
by Antonio Linares
Ehab,

Instead of doing:

oExcel:WorkBooks:Add()

try:

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

Posted: Fri Mar 24, 2006 10:15 am
by Ehab Samir Aziz
I tried this but the exe file closed by itself without any errors but where is the file created ?

Code: Select all

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

Posted: Fri Mar 24, 2006 12:13 pm
by Antonio Linares
Ehab,

This is the right code:

Code: Select all

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 

Posted: Fri Mar 24, 2006 12:24 pm
by Ehab Samir Aziz
ok. That what I finished to . The Excel sheet opened but no data written to it .

Code: Select all

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

Posted: Fri Mar 24, 2006 12:27 pm
by Antonio Linares
Ehab,

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