Page 1 of 1

Insert Row/Column into Excel

Posted: Mon Nov 26, 2007 1:43 am
by Jonathan Hodder
Can anyone tell me how to insert a new row using OLE?

Re: Insert Row/Column into Excel

Posted: Mon Nov 26, 2007 9:24 am
by Enrico Maria Giordano

Code: Select all

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

Posted: Mon Nov 26, 2007 8:56 pm
by Jonathan Hodder
Thanks Enrico

Posted: Tue Nov 27, 2007 6:25 pm
by kajot
what may I do, I can't open application Excell but write sheet to file

Posted: Tue Nov 27, 2007 6:29 pm
by Enrico Maria Giordano
Replace

Code: Select all

oExcel:Visible = .T.
with

Code: Select all

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

oExcel:Quit()
EMG

Posted: Tue Nov 27, 2007 6:38 pm
by kajot
thanks You
I want to open two folder in one sheet

Posted: Tue Nov 27, 2007 10:47 pm
by Enrico Maria Giordano

Code: Select all

oSheet = oWorkSheets:Add()
You should start to seriously review Excel docs. :-)

EMG

Posted: Wed Nov 28, 2007 12:29 pm
by Otto
Enrico, could you please help me on that.
Thanks in advance
Otto
Unresolved external '_HB_FUN_CREATEOBJECT' referenced from C:\FWH\SAMPLES

Posted: Wed Nov 28, 2007 3:50 pm
by Enrico Maria Giordano
If you are using Harbour you have to use TOleAuto():New() instead of CreateObject().

EMG

Posted: Wed Nov 28, 2007 4:14 pm
by Otto
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

Posted: Wed Nov 28, 2007 6:35 pm
by Enrico Maria Giordano
I forgot to say that you need hbole.lib or hbwin32.lib.

EMG

Posted: Wed Nov 28, 2007 6:36 pm
by Antonio Linares
Otto,

You have to link HbWin32.lib from Harbour

Posted: Wed Nov 28, 2007 9:00 pm
by Otto
Where can I download HbWin32.lib ?
Regards,
Otto

Posted: Wed Nov 28, 2007 9:49 pm
by Antonio Linares
Otto,

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

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

Posted: Wed Nov 28, 2007 9:57 pm
by Otto
Thank you Enrico and Antonio.

Image