EXCEL and FWH
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
EXCEL and FWH
Is there a Direct way of dealing with Excel and extract data from .dbf under some conditions to constitute Excel files ?
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
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.
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
There is no a class called createobject .
I tried that code with errors of non existence to 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
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
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
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Ehab,
This is the right code:
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
-
- Posts: 334
- Joined: Fri Oct 14, 2005 1:54 pm
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
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact: