EXCEL and FWH

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

EXCEL and FWH

Post 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 ?
User avatar
betoncu
Posts: 120
Joined: Sat Oct 08, 2005 9:38 pm
Location: Cyprus (North)

Post 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.
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post 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
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post by Ehab Samir Aziz »

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

Post 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 ?
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post 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 ?
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Ehab,

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

Antonio Linares
www.fivetechsoft.com
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post 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)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Ehab,

Instead of doing:

oExcel:WorkBooks:Add()

try:

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

Antonio Linares
www.fivetechsoft.com
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post 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 
regards, saludos

Antonio Linares
www.fivetechsoft.com
Ehab Samir Aziz
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Ehab,

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

Antonio Linares
www.fivetechsoft.com
Post Reply