tewelch has asked for the wisdom of the Perl Monks concerning the following question:

I'm building a script to generate a powerpoint document
based on a database query and am having trouble creating
a filled rectangle shape. Seems like the correct way is
(based on a ppt macro that does it):
$Slide->Shapes->AddShape({msoShapeRectangle,Left=>72,Top=>72,Width=>25 +2,Height=>48});
but I get the error message:
Win32::OLE(0.1601) error 0x80020006: "Unknown name" "msoShapeRectangle", "48", "72" and "252" in Get
Any ideas ?
Thanks in advance.

edited: Fri Oct 24 18:03:05 2003 by jeffa - removed unclosed pre section, replaced with code tags

Replies are listed 'Best First'.
Re: Win32::OLE PowerPoint Shapes
by jsprat (Curate) on Oct 25, 2003 at 05:26 UTC
    Perl knows not what msoShapeRectangle is. You need to import the constants from the Office type library or supply them yourself.

    Try something like this

    use Win32::OLE; use Win32::OLE::Const 'Microsoft Office'; print msoShapeRectangle . ":" . msoShapeOval; __END__ results: 1:9

      Thankyou. I've got the shape added but now I'm stumped on how to set the fill color. Based on a ppt macro that does the same thing I think the perl code should be something like:
      $colorBox->Fill->{ForeColor} = ({Red=>255, Green=>255, Blue=>153});
      but this results in the error:
      Win32::OLE(0.1601) error 0x80020005: "Type mismatch" in PROPERTYPUT "ForeColor" at build_ql.prl line 121
      Any suggestions ?
Re: Win32::OLE PowerPoint Shapes
by rdfield (Priest) on Oct 24, 2003 at 15:16 UTC
    Looks like you're missing a comma to me. The hash reads as msoShapeRectangle => Left, 72 => Top, etc since => is just a "fat" comma.

    rdfield

Re: Win32::OLE PowerPoint Shapes
by Solo (Deacon) on Oct 30, 2003 at 20:29 UTC
    My quick look at PPT's help got me this VB example:

    With myDocument.Shapes.AddShape(Type:=msoShapeRectangle, _ Top:=144, Left:=144, Width:=72, Height:=72) .Name = "Red Square" .Fill.ForeColor.RGB = RGB(255, 0, 0) .Line.DashStyle = msoLineDashDot End With
    Which is not exactly in line with yours, but is close enough for MS work.

    What caught my eye is the use of a VB function cleverly called RGB. Referencing the docs, one finds function RGB converts three arguments into a LONG representing the color. Here's a snippet from my VB's immediate window test cases.

    print RGB(0,0,0) 0 print RGB(255,255,255) 16777215 print RGB(255,0,0) 255 print RGB(0,255,0) 65280 print RGB(0,0,255) 16711680
    This function, at least, seems to perform as documented.

    Armed with this knowledge, I constructed a Perl example that strives to curve-fit the MS function.

    sub RGB { my ($red,$green,$blue) = @_; return $red + 256 * $green + 65536 * $blue; } print RGB(0,0,0) . "\n"; print RGB(255,255,255) . "\n"; print RGB(255,0,0) . "\n"; print RGB(0,255,0) . "\n"; print RGB(0,0,255) . "\n";
    As you can see, the Perl function fits the VB data well within the expected error.
    0 16777215 255 65280 16711680
    There is no guarantee that our Perl port of VB's RGB function will solve your problem, but it should provide a good jumping-off point.

    <Oobject name="tongue" method="in-cheek" comment="intended with best regards =)"/>

    --Solo

    --
    You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.