Microsoft Office Automation with Visual FoxPro

Putting it all together

Listing 4 shows a few slides for a marketing presentation for Tasmanian Traders. The slides show what is covered in this chapter. The program creates three slides, shown in Figures 10, 11, and 12.

Listing 4. A sample presentation for Tasmanian Traders.

CLOSE DATA

#DEFINE ppLayoutTitle 1

#DEFINE ppLayoutText 2

#DEFINE ppBulletArabicPeriod 3

#DEFINE msoLineThickBetweenThin 5

#DEFINE autoIn2Pts 72

* Clean out any existing references to servers.

* This prevents memory loss to leftover instances.

RELEASE ALL LIKE o*

* For demonstration purposes, make oPowerPoint and oPresentation

* available after this program executes.

PUBLIC oPowerPoint, oPresentation

SET PATH TO _SAMPLES + "\TasTrade\Data\"

* Set up the data

OPEN DATABASE "TasTrade"

LogoFile = _SAMPLES + "\TasTrade\Bitmaps\TTradeSm.bmp"

USE OrdItems IN 0

USE Products IN 0

* Select the top 5 selling items of all time

SELECT TOP 5 ;

P.English_Name, ;

SUM(O.Unit_Price * O.Quantity) AS TotQuan ;

FROM OrdItems O, Products P ;

WHERE O.Product_ID = P.Product_ID ;

GROUP BY 1 ;

ORDER BY 2 DESC;

INTO CURSOR TopSellers

* Select the number of products

SELECT Count(*) ;

FROM Products ;

INTO ARRAY aProducts

* Open PowerPoint

oPowerPoint = CreateObject("PowerPoint.Application")

oPowerPoint.Visible = .T.

* Create the presentation

oPresentation = oPowerPoint.Presentations.Add()

SlideNum = 1

 

Figure 10. The Tasmanian Traders sample title slide. This slide demonstrates adding graphics and changing text attributes.

* TITLE SLIDE............

* Add the slide

oSlide = oPresentation.Slides.Add(SlideNum, ppLayoutTitle)

* Set the title text. Change it to Arial font, blue, and bold.

WITH oSlide.Shapes[1].TextFrame.TextRange

.Text = "Tasmanian Traders"

WITH .Font

.Name = "Arial"

.Bold = .T.

.Color = RGB(0, 0, 128)

ENDWITH

ENDWITH

* Set the subtitle text

oSlide.Shapes[2].TextFrame.TextRange.Text = "Welcomes you..."

* Add the logo.

oSlide.Shapes.AddPicture(LogoFile, .F., .T., ;

2.0 * autoIn2Pts, 1.5 * autoIn2Pts)

* PowerPoint 97 users: the last two parameters,

* height and width, are not optional. Use this

* code instead:

*.Shapes.AddPicture(LogoFile, .F., .T., ;

* 8.5 * autoIn2Pts, 6.0 * autoIn2Pts, ;

* 1.0 * autoIn2Pts, 1.0 * autoIn2Pts)

SlideNum = SlideNum + 1

 

Figure 11. The Tasmanian Traders sample second slide. This slide demonstrates adding lines and changing attributes for a segment of text.

* SECOND SLIDE...........

* Add the slide

oSlide = oPresentation.Slides.Add(SlideNum, ppLayoutTitle)

* Bring the slide to the front

oSlide.Select()

* PowerPoint 97 users: oSlide.Select() will

* generate an error. Use this line instead:

* oPresentation.ActiveWindow.View.GoToSlide(2)

* Set the text of the title

WITH oSlide.Shapes[1].TextFrame.TextRange

.Text = "Tasmanian Traders " + CHR(13) + "has what you need"

WITH .Font

.Name = "Arial"

.Bold = .T.

.Color = RGB(0,0,128)

ENDWITH

ENDWITH

* Move the title up about half an inch

WITH oSlide.Shapes(1)

.Top = .Top - (.5 * autoIn2Pts)

ENDWITH

* Add a line half an inch below the title that is centered and 6" long

LineTop = oSlide.Shapes[1].Top + oSlide.Shapes[1].Height + ;

(.5 * autoIn2Pts)

LineLeft = 2 * autoIn2Pts

LineEnd = LineLeft + (6.0 * autoIn2Pts)

oLine = oSlide.Shapes.AddLine(LineLeft, LineTop, LineEnd, LineTop)

* Format the line to be red, and make it a thick line

* with two thin lines on either side

WITH oLine.Line

.ForeColor.RGB = RGB(255,0,0)

.Style = msoLineThickBetweenThin

.Weight = 8

ENDWITH

* Set the text of the subtitle, and change the number to bold and red.

WITH oSlide.Shapes[2].TextFrame.TextRange

.Text = "With a selection of " + ALLTRIM(STR(aProducts[1])) + ;

" items, you're sure to be pleased."

.Words[5].Font.Bold = .T.

.Words[5].Font.Color = RGB(255, 0, 0)

ENDWITH

SlideNum = SlideNum + 1

Figure 12. The Tasmanian Traders sample third slide. This slide demonstrates adding bulleted lists.

* TOP 5 SELLERS SLIDE..........

* Add the slide

oSlide = oPresentation.Slides.Add(SlideNum, ppLayoutText)

* Bring the slide to the front

oSlide.Select()

* PowerPoint 97 users: oSlide.Select() will

* generate an error. Use this line instead:

* oPresentation.ActiveWindow.View.GoToSlide(2)

* Insert the title (note the use of the Title object, instead of

* an enumerated shape object). Make the font Arial, blue, and bold.

WITH oSlide.Shapes.Title.TextFrame.TextRange

.Text = "Tasmanian Traders" + CHR(13) + "Top Sellers"

WITH .Font

.Name = "Arial"

.Bold = .T.

.Color = RGB(0,0,128)

ENDWITH

ENDWITH

* Build the string to use for the top 5 sellers.

* Use a CR between each item to make each a separate bullet.

BulletString = ""

SELECT TopSellers

SCAN

BulletString = BulletString + ;

TRIM(TopSellers.English_Name) + " -- $" + ;

ALLTRIM(TRANSFORM(TopSellers.TotQuan, "99,999,999")) + ;

CHR(13)

ENDSCAN

* Add the bullet string to the text frame, and make the bullets numeric.

WITH oSlide.Shapes[2].TextFrame.TextRange

.Text = BulletString

.ParagraphFormat.Bullet.Style = ppBulletArabicPeriod && Available only

&& in PowerPoint 2000

ENDWITH

* Run the slide show.

oPresentation.SlideShowSettings.Run()

Now you are capable of producing a slide show that is sure to knock the socks off your client. But wait, there s more! In addition to these basic features, PowerPoint throws in some advanced features FREE! The next chapter explains some of the advanced features of PowerPoint.

Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved

Категории