FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Excel works with xHarbour, not Harbour
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Excel works with xHarbour, not Harbour
Posted: Mon Jun 18, 2012 06:27 PM
The following function works with xHarbour ( .com ) / xCC / FWH 12.04.

It returns the message that Excel is not available when using Harbour / MSVC 2010 / FWH 12.04

Code (fw): Select all Collapse
FUNCTION ARToXls( aCodes, cTitle )
    *-----------------
    LOCAL oExcel, oAS
    LOCAL nRow, nCol, aStruct, i
    LOCAL nACnt := LEN( aCodes )
    nRow := nCol := nCtr := 0

    // Create the object
    oExcel := CreateObject( "Excel.Application" )

    IF Ole2TxtError() != "S_OK"
        ALERT ( "ERROR! Excel not available." )
        RETURN
    ENDIF

    oExcel:WorkBooks:Add( )
    oAS := oExcel:ActiveSheet( )

    oAS:Cells:Font:Name := "MS Sans Serif"
    oAS:Cells:Font:Size := 10

    oAS:Cells( 1, 1 ):Value :=  "Company             "
    oAS:Cells( 1, 2 ):Value :=  "Current   "
    oAS:Cells( 1, 3 ):Value :=  "Begin Bal."
    oAS:Cells( 1, 4 ):Value :=  "January   "
    oAS:Cells( 1, 5 ):Value :=  "February  "
    oAS:Cells( 1, 6 ):Value :=  "March     "
    oAS:Cells( 1, 7 ):Value :=  "April     "
    oAS:Cells( 1, 8 ):Value :=  "May       "
    oAS:Cells( 1, 9 ):Value :=  "June      "
    oAS:Cells( 1, 10):Value :=  "July      "
    oAS:Cells( 1, 11 ):Value := "August    "
    oAS:Cells( 1, 12 ):Value := "September "
    oAS:Cells( 1, 13 ):Value := "October   "
    oAS:Cells( 1, 14 ):Value := "November  "
    oAS:Cells( 1, 15 ):Value := "December  "

    FOR nRow := 1 TO nACnt
        oAS:Cells( nRow+1, 1 ):Value := aCodes[nRow][1]
        FOR i := 2 TO 15
            oAS:Cells( nRow+1, i ):Value := STR( aCodes[nRow][i], 12, 2 )
        NEXT
    NEXT

   FOR i = 1 to nACnt
      oAS:Columns( i ):AutoFit()
   NEXT

    oExcel:Visible := .T.
    oExcel:ActiveWorkbook:SaveAs( cTitle )
    oExcel:ActiveWindow:Close()
    oExcel:Quit()
    MsgInfo( cTitle + " has been created in your document folder" )
RETURN


I have had other problems with Active X operations using Harbour 3.0 and FWH 12.

Any thoughts on this problem ?

Thanks.

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Excel works with xHarbour, not Harbour
Posted: Tue Jun 19, 2012 03:12 PM
Tim,

It seems as Ole2TxtError() is not returning the right value.

If you comment out this code, then your example is working fine:

Code (fw): Select all Collapse
    
   /*
   IF Ole2TxtError() != "S_OK"
        ALERT ( "ERROR! Excel not available." )
        RETURN
   ENDIF
   */
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Excel works with xHarbour, not Harbour
Posted: Tue Jun 19, 2012 03:17 PM

Thank you ... another difference between harbour and xharbour ...

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Excel works with xHarbour, not Harbour
Posted: Mon Jun 25, 2012 12:12 PM

May I suggest using Fivewin function ExcelObj() to create excel object?

oExcel := ExcelObj()
if oExcel == nil
// excel not installed or could not be started
else
// proceed using oExcel
endif

This function is working well with xHarbour and Harbour ( bcc 582 ) and with xhb ( commerical )

Regards



G. N. Rao.

Hyderabad, India
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Excel works with xHarbour, not Harbour
Posted: Mon Jun 25, 2012 05:46 PM

Thank you. ExcelObj( ) resolves the problem and works fine with xHarbour ( .com ) and Harbour/MSVC 2010.

Tim

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit

Continue the discussion