Ms-Excel code to FWH

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Ms-Excel code to FWH

Post by Jeff Barnes »

Hi Everybody,

Can someone please help me convert this to FWH.

Code: Select all

Sub InsertPicture()

    Dim oSheet As Worksheet
    Dim cBMP1 As String
    Dim cBMP2 As String
    Dim rngOutput As Range
    
    Set oSheet = ActiveSheet
    
    cBMP1 = "C:\temp\a.bmp"
    Set rngOutput = oSheet.Range("A1", "A1")
    With oSheet.Pictures.Insert(cBMP1)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With

    cBMP2 = "C:\temp\b.bmp"
    Set rngOutput = oSheet.Range("A61", "A61")
    With oSheet.Pictures.Insert(cBMP2)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With
    
End Sub

The area I'm most stuck with is:

Code: Select all

    With oSheet.Pictures.Insert(cBMP2)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Ms-Excel code to FWH

Post by Enrico Maria Giordano »

Jeff Barnes wrote:The area I'm most stuck with is:

Code: Select all

    With oSheet.Pictures.Insert(cBMP2)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With

Code: Select all

WITH oSheet:Pictures:Insert(cBMP2)
    :Left = rngOutput:Left
    :Top = rngOutput:Top
END
EMG
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

I need a bit more help with this one...

I try to use the code:

Code: Select all

   rngOutput := oSheet:Range("A1","A1")
   oSheet:Pictures:Insert(cLogo)
   WITH
     :Left = rngOutput:Left
     :Top = rngOutput:Top
   END
But I get the following errors when I compile...
Compiling...
xHarbour Compiler build 0.99.71 (SimpLex)
Copyright 1999-2007, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'EzSat.prg' and generating preprocessed output to 'EzSat.ppo'...
EzSat.prg(5714) Error E0030 Syntax error: "parse error at 'OSHEET'"
EzSat.prg(5715) Error E0054 WITH Message [LEFT] with no WITH OBJECT in sight.
EzSat.prg(5716) Error E0054 WITH Message [TOP] with no WITH OBJECT in sight.
EzSat.prg(5721) Error E0010 ENDIF does not match IF
4 errors

No code generated
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
EzSat.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
* Application successfully built

Any ideas?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

There was a typo ... the code giving me the error is:

Code: Select all

rngOutput := oSheet:Range("A1","A1")
   WITH oSheet:Pictures:Insert(cLogo)
     :Left = rngOutput:Left
     :Top = rngOutput:Top
   END 
And the error is:
Compiling...
xHarbour Compiler build 0.99.71 (SimpLex)
Copyright 1999-2007, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'EzSat.prg' and generating preprocessed output to 'EzSat.ppo'...
EzSat.prg(5714) Error E0030 Syntax error: "parse error at 'OSHEET'"
EzSat.prg(5715) Error E0054 WITH Message [LEFT] with no WITH OBJECT in sight.
EzSat.prg(5716) Error E0054 WITH Message [TOP] with no WITH OBJECT in sight.
EzSat.prg(5721) Error E0010 ENDIF does not match IF
4 errors

No code generated
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
EzSat.c:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
* Application successfully built
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Post by mmercado »

Hi Jeff:

Just guessing:

Code: Select all

oSheet:Pictures:Insert(cBMP2):Left = rngOutput.Left 
         oSheet:Pictures:Insert(cBMP2):Top = rngOutput.Top 

or

oPict := oSheet:Pictures:Insert(cBMP2)
oPict:Left = rngOutput.Left 
oPict:Top = rngOutput.Top 
         
Regards

Manuel Mercado
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

I've tried Manuel and Enrico's examples with no luck.
I made a small test program to make it easier.

Code: Select all

#Include "Fivewin.ch"

Function Main()
   Local oExcel, oSheet, rngOutput, cLogo:="\EzSat\Logo.bmp"

   oExcel := TOleAuto():New( "Excel.Application" )
   oSheet := oExcel:Get("ActiveSheet")
   oExcel:Set( "DisplayAlerts", .T.)
   oExcel:Set( "Visible", .T.)
   
   rngOutput := oSheet:Range("A1","A1")
   WITH oSheet:Pictures:Insert(cLogo) 
      :Left=rngOutput:Left 
      :Top=rngOutput:Top
   END 
Return Nil

When I compile the above code I get the following error when I compile the program:
Compiling...
xHarbour Compiler build 0.99.71 (SimpLex)
Copyright 1999-2007, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'testexcel.prg' and generating preprocessed output to 'testexcel.ppo'.
..
testexcel.prg(12) Error E0030 Syntax error: "parse error at 'OSHEET'"
testexcel.prg(13) Error E0054 WITH Message [LEFT] with no WITH OBJECT in sight.

testexcel.prg(14) Error E0054 WITH Message [TOP] with no WITH OBJECT in sight.
testexcel.prg(15) Error E0030 Syntax error: "parse error at 'END'"
4 errors

No code generated
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
Error E2194: Could not find file 'testexcel.c'
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Fatal: Unable to open file 'TESTEXCEL.OBJ'
* There are errors
Can anyone see where I am going wrong? Am I leaving something out?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Post by mmercado »

Hi Jeff:

Here you are a similar working sample:

Code: Select all

#include "fivewin.ch"

Function Main()

   Local oWnd, oMenu

   MENU oMenu
      MENUITEM "Picture to Excel" ACTION XlsImage( "\FWH\BitMaps\Cara.bmp" )
      MENUITEM "Exit" ACTION oWnd:End()
   ENDMENU

   DEFINE WINDOW oWnd MENU oMenu
   Activate WINDOW oWnd MAXIMIZED

Return Nil

Static Function XlsImage( cFile )

   Local oExcel, oSheet, oImg

   oExcel := TOleAuto():New("Excel.Application")
   oExcel:WorkBooks:Add()
   oSheet := oExcel:Get( "ActiveSheet" )
   oSheet:Range( "B5:B5" ):Select()
   oImg := oSheet:Pictures:Insert( cFile )
   oImg:Select()
   oExcel:Visible := .T.
   OleUninitialize()

Return Nil
Regards.

Manuel Mercado
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Hi Manuel,

Your method is basically the way I normally insert an image.

The problem I am having is that Excel 2007 works differently than previous versions of Excel.

When I use the code in your example with 2007 the images do not go into the selected cells.

I went on an Excel newsgroup and it was suggested that I do it the following way:
(http://www.excelforum.com/showthread.ph ... ost1917614)

Code: Select all

Sub InsertPicture()

    Dim oSheet As Worksheet
    Dim cBMP1 As String
    Dim cBMP2 As String
    Dim rngOutput As Range
   
    Set oSheet = ActiveSheet
   
    cBMP1 = "C:\temp\a.bmp"
    Set rngOutput = oSheet.Range("A1", "A1")
    With oSheet.Pictures.Insert(cBMP1)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With

    cBMP2 = "C:\temp\b.bmp"
    Set rngOutput = oSheet.Range("A61", "A61")
    With oSheet.Pictures.Insert(cBMP2)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With
   
End Sub
So I am trying to convert this code to FWH so I can insert the images using Excel 2007.


[/url]
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Jeff Barnes wrote:I've tried Manuel and Enrico's examples with no luck.
I made a small test program to make it easier.
Now I see the error. Replace

Code: Select all

WITH oSheet:Pictures:Insert(cLogo)
with

Code: Select all

WITH OBJECT oSheet:Pictures:Insert(cLogo)
EMG
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

It is working Now.

Thanks once again
:D
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
Post Reply