FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Insert Row/Column into Excel
Posts: 77
Joined: Sun Aug 26, 2007 11:53 PM
Insert Row/Column into Excel
Posted: Mon Nov 26, 2007 01:43 AM

Can anyone tell me how to insert a new row using OLE?

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Insert Row/Column into Excel
Posted: Mon Nov 26, 2007 09:24 AM
FUNCTION MAIN()

    LOCAL oExcel := CREATEOBJECT( "Excel.Application" )

    LOCAL oWorkbook := oExcel:Workbooks:Add()

    LOCAL oSheet := oExcel:ActiveSheet

    oSheet:Cells( 1, 1 ):Value = "Test 1A"
    oSheet:Cells( 1, 2 ):Value = "Test 1B"

    oSheet:Cells( 2, 1 ):Value = "Test 3A"
    oSheet:Cells( 2, 2 ):Value = "Test 3B"

    oSheet:Rows( 2 ):Insert()

    oSheet:Cells( 2, 1 ):Value = "Test 2A"
    oSheet:Cells( 2, 2 ):Value = "Test 2B"

    oExcel:Visible = .T.

    RETURN NIL


EMG
Posts: 77
Joined: Sun Aug 26, 2007 11:53 PM
Insert Row/Column into Excel
Posted: Mon Nov 26, 2007 08:56 PM

Thanks Enrico

Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Insert Row/Column into Excel
Posted: Tue Nov 27, 2007 06:25 PM

what may I do, I can't open application Excell but write sheet to file

best regards

kajot
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Insert Row/Column into Excel
Posted: Tue Nov 27, 2007 06:29 PM
Replace

oExcel:Visible = .T.


with

oSheet:SaveAs( "c:\xharbour\newfile.xls" )

oExcel:Quit()


EMG
Posts: 357
Joined: Thu Nov 02, 2006 06:53 PM
Insert Row/Column into Excel
Posted: Tue Nov 27, 2007 06:38 PM

thanks You
I want to open two folder in one sheet

best regards

kajot
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Insert Row/Column into Excel
Posted: Tue Nov 27, 2007 10:47 PM
oSheet = oWorkSheets:Add()


You should start to seriously review Excel docs. :-)

EMG
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 12:29 PM

Enrico, could you please help me on that.
Thanks in advance
Otto
Unresolved external '_HB_FUN_CREATEOBJECT' referenced from C:\FWH\SAMPLES

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 03:50 PM

If you are using Harbour you have to use TOleAuto():New() instead of CreateObject().

EMG

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 04:14 PM

Hello Enrico,
Thank you for your help. But I can’t get it working.

I have a original FWH installation 7.11 with original FIVEWIN harbour.

I get this error. The only other file with TOleAuto in Fivewin\samples
is mscomm32.prg. If you compile this file you have the same error.

Error: Unresolved external '_HB_FUN_TOLEAUTO' referenced from C:\FWH\SAMPLES\MSC
OMM32.OBJ

Thanks in advance
Otto

FUNCTION MAIN()
// LOCAL oExcel := CREATEOBJECT( "Excel.Application" )
LOCAL oExcel := TOleAuto( ):New( "Excel.Application" )
LOCAL oWorkbook := oExcel:Workbooks:Add()
LOCAL oSheet := oExcel:ActiveSheet

oSheet:Cells( 1, 1 ):Value = "Test 1A"
oSheet:Cells( 1, 2 ):Value = "Test 1B"
oSheet:Cells( 2, 1 ):Value = "Test 3A"
oSheet:Cells( 2, 2 ):Value = "Test 3B"
oSheet:Rows( 2 ):Insert()
oSheet:Cells( 2, 1 ):Value = "Test 2A"
oSheet:Cells( 2, 2 ):Value = "Test 2B"
oExcel:Visible = .T.

//oSheet:SaveAs( "c:\xharbour\newfile.xls" )
//oExcel:Quit()

RETURN NIL

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 06:35 PM

I forgot to say that you need hbole.lib or hbwin32.lib.

EMG

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 06:36 PM

Otto,

You have to link HbWin32.lib from Harbour

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 09:00 PM

Where can I download HbWin32.lib ?
Regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 09:49 PM

Otto,

http://rapidshare.com/files/72966698/hbwin32.lib.html

Have you checked if it is included in Harbour libs directory ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Insert Row/Column into Excel
Posted: Wed Nov 28, 2007 09:57 PM
Thank you Enrico and Antonio.

Continue the discussion