Ms-Excel code to FWH

Ms-Excel code to FWH

Postby Jeff Barnes » Wed May 14, 2008 7:57 pm

Hi Everybody,

Can someone please help me convert this to FWH.

Code: Select all  Expand view
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  Expand view
    With oSheet.Pictures.Insert(cBMP2)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Ms-Excel code to FWH

Postby Enrico Maria Giordano » Thu May 15, 2008 7:16 am

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

Code: Select all  Expand view
    With oSheet.Pictures.Insert(cBMP2)
        .Left = rngOutput.Left
        .Top = rngOutput.Top
    End With


Code: Select all  Expand view
WITH oSheet:Pictures:Insert(cBMP2)
    :Left = rngOutput:Left
    :Top = rngOutput:Top
END


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Jeff Barnes » Fri May 16, 2008 2:25 pm

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

I try to use the code:

Code: Select all  Expand view
   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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Jeff Barnes » Fri May 16, 2008 2:28 pm

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

Code: Select all  Expand view
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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby mmercado » Fri May 16, 2008 2:58 pm

Hi Jeff:

Just guessing:

Code: Select all  Expand view
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
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby Enrico Maria Giordano » Fri May 16, 2008 3:00 pm

There are no errors in the portion of code you reported.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Jeff Barnes » Fri May 16, 2008 7:14 pm

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

Code: Select all  Expand view
#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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby mmercado » Sat May 17, 2008 12:38 am

Hi Jeff:

Here you are a similar working sample:
Code: Select all  Expand view
#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
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby Jeff Barnes » Sat May 17, 2008 2:50 am

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  Expand view
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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Postby Enrico Maria Giordano » Sat May 17, 2008 12:34 pm

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  Expand view
WITH oSheet:Pictures:Insert(cLogo)


with

Code: Select all  Expand view
WITH OBJECT oSheet:Pictures:Insert(cLogo)


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Jeff Barnes » Sun May 18, 2008 10:49 pm

It is working Now.

Thanks once again
:D
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 107 guests