FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour EXCEL and FWH
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: Sun Mar 19, 2006 06:14 AM

Is there a Direct way of dealing with Excel and extract data from .dbf under some conditions to constitute Excel files ?

Posts: 130
Joined: Sat Oct 08, 2005 09:38 PM
EXCEL and FWH
Posted: Sun Mar 19, 2006 07: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.

Birol Betoncu
birol.betoncu@gmail.com
Using Harbour, FWH 19.05, BCC7
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: 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:
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
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
EXCEL and FWH
Posted: Tue Mar 21, 2006 02:02 PM
Ehab Samir Aziz wrote:There is no a class called createobject .


You have to use xHarbour or link hbole.lib.

EMG
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: Tue Mar 21, 2006 05:29 PM

Can you help me of code that helps me to Extract DBF fields values to Excel sheet ?

Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
EXCEL and FWH
Posted: Tue Mar 21, 2006 05:32 PM

Betoncu sample is fine.

EMG

Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: Tue Mar 21, 2006 09: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 ?

Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: 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 ?
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
EXCEL and FWH
Posted: Fri Mar 24, 2006 07:51 AM

Ehab,

Please change CreateObject() into CreateOleObject()

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: Fri Mar 24, 2006 09: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)

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
EXCEL and FWH
Posted: Fri Mar 24, 2006 09:37 AM

Ehab,

Instead of doing:

oExcel:WorkBooks:Add()

try:

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: 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 ?

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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
EXCEL and FWH
Posted: Fri Mar 24, 2006 12:13 PM
Ehab,

This is the right code:
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
Posts: 334
Joined: Fri Oct 14, 2005 01:54 PM
EXCEL and FWH
Posted: Fri Mar 24, 2006 12:24 PM
ok. That what I finished to . The Excel sheet opened but no data written to it .

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
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
EXCEL and FWH
Posted: 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