Adding a new sheet in an Excel workbook (OLE)

658 views
Skip to first unread message

imozes

unread,
Jul 8, 2013, 8:43:11 AM7/8/13
to harbou...@googlegroups.com
Hello
 
I would like to add a new sheet in an Excel workbook, calling Worksheets:Add() method, through OLE.
The firs argument is "Before" the  second is "After" and both are optional.
My new worksheet must be the last, so I should specify the second argument, omitting the first.
 
How can I do it ?
 
I tried
    oBook:Worksheets:Add(,oBook:ActiveSheet)
but it does not work because of the first argument, returns the error:
ADD: DISP_E_BADPARAMCOUNT; arguments: NIL { TOLEAUTO Object }
 
Thanks in advance,
IMozes
 

Miraš Ćirović

unread,
Jul 8, 2013, 9:54:20 AM7/8/13
to harbou...@googlegroups.com
Hi!
This is an example for excel.

Procedure SnimiXLSTSI()
   LOCAL oExcel, oHoja, nRows, nCols, cDatXls
   LOCAL aCampos:={}, nRow, nCol
   Private POZR
   cDatXls := GetStartUpFolder() + "\" +"example.xls"
   msginfo(cDatXls)
   oExcel := CreateObject( "Excel.Application")
    if Ole2TxtError() != 'S_OK'
         MsgInfo('Excel nije instaliran','Upozorenje')
         Return
    endif
   oExcel:Visible := .T.
   oExcel:Workbooks:Open( cDatXls)
   oExcel:Set("data",.F.) //
   oExcel:Sheets("data"):Select()
   oHoja:=oExcel:Get( "ActiveSheet" )
  
   oHoja:Range("B3"):Value := "data"
 
    *** New Sheets***

    oExcel:Set("PodDada",.F.) //
    oExcel:Sheets("PodData"):Select()
    oHoja:=oExcel:Get( "ActiveSheet" )

   oHoja:Cells( 17, 11 ):Value := 2563

*  oExcel:Quit()
*  oHoja:End()
*  oExcel:End()
Return

This is an example for calcl.

Procedure SnimiCalc()
local oServiceManager,oDesktop,oDocument,oSchedule,oSheet,oCell,oColums,oColumn,cDatXls

 // inicijalizacija

 IF (  oServiceManager := TOleAuto():New("com.sun.star.ServiceManager") ) != NIL
   oDesktop := oServiceManager:createInstance("com.sun.star.frame.Desktop")
   IF oDesktop = NIL
      MsgStop('OpenOffice Calc nije instaliran','error')
      RETURN Nil
   ENDIF
   cDatXls := GetStartUpFolder() + "\" +"data.xls"
   IF FILE(cDatXls)
      cDatXls:="file:///"+cDatXls
      oDocument := oDesktop:loadComponentFromURL(cDatXls,"_blank", 0, {})
   ELSE
      oDocument := oDesktop:loadComponentFromURL("private:factory/scalc","_blank", 0, {})
   ENDIF
   oSchedule := oDocument:GetSheets() 
   oSheet := oSchedule:GetByName("Opci")
   oSheet:getCellRangeByName( "E5" ):setString(ctod("01.01.2013")
   oSheet:getCellRangeByName( "H5" ):setString(ctod("31.12.2013")
   oSheet:getCellRangeByName( "E9" ):setValue( 5 )
   oSheet:getCellRangeByName( "C17" ):setValue( 10 )
 
  *******New sheet*****
           oSheet := oSchedule:GetByName("PodData")

     oSheet:getCellRangeByName( "C17" ):setValue( 10 )
 
 endif
Return

You must have installed both applications(excel and OpenOffice.

Best Regards,
Miraš


2013/7/8 imozes <imo...@gmail.com>
 

--
--
You received this message because you are subscribed to the Google
Groups "Harbour Users" group.
Unsubscribe: harbour-user...@googlegroups.com
Web: http://groups.google.com/group/harbour-users
 
---
You received this message because you are subscribed to the Google Groups "Harbour Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Alen Sacaric

unread,
Jul 25, 2014, 9:19:00 AM7/25/14
to harbou...@googlegroups.com
Ciro, can you please help me.
With your example for Excel, I get strange error (HMG 3.3.0):

Error WINOLE/1009 No exported method: SET (DOS Error-2147352570)

Called from TOLEAUTO:SET(0)
Called from SnimiXLSTSI(94)
Called from (b)MAIN(18)

Thank you!
Reply all
Reply to author
Forward
0 new messages