Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

The Baker's Dozen: 13 Productivity Tips for Generating PowerPoint Presentations : Page 4

In this installment of "The Baker's Dozen" you'll get some handy tips on creating Office eye candy: generating PowerPoint output.


advertisement
Tip 8: Customizing the Display of an Excel Chart Object
Listing 5 demonstrates how to create an Excel chart, using the method BuildExcelPieChart. Building a pie chart (and for the most part, building any chart) involves the following:

  • Calling BuildExcelTable with a DataTable containing the data for the chart
  • Adding a new chart
  • Using either ActiveChart.ChartType or ApplyCustomType to define the type of chart. IntelliSense will provide the list of available chart types.
  • Setting the source data for the active chart using the cell range that BuildExcelTable returns.
  • Setting other properties relevant to the chart type (Legend, X and Y axis, etc.)
  • Setting the ColorIndex and LineStyle of the chart's ChartArea and PlotArea. This is very important to the overall display of the chart.
  • Selecting the entire chart area and copying it to the Windows clipboard
Tip 9: Creating a Slide that Displays Both a Table and a Pie Chart
This solution demonstrates how C# and Visual Basic can be used together in Visual Studio 2005. Both languages and associated development environments have their respective strengths.

The code in Listing 4 directly calls the GenPPT method BuildTablePieChartPage (Listing 6) to build the slide with a table and a chart (to produce Figure 4). BuildTablePieChartPage does the following:

  • Creates a new slide based on the ppLayoutTextAndChart layout.
  • Adds a slide title
  • Calls BuildExcelTable for the table data, and pastes the results into the table section of the slide.
  • Calls BuildExcelPieChart for the chart data, and pastes the results into the chart section of the slide.
  • Set other properties relevant to the chart type (Legend, X and Y axis, etc.)
 
Figure 5: Generating a line chart.
Tip 10: Creating a Slide that Displays a Line Chart
Now that you've displayed a chart as part of a slide, you'll now learn to create a chart that occupies the entire slide. Figure 5 shows a line chart that plots the weekly quarterback rating of Chiefs' quarterback Trent Green through the 2003 and 2004 seasons.

Once again, you'll create data to drive the table (see Listing 7), and then call a method to build the Line Chart page (see Listing 8). Similar to Tip 9, this method will create a new slide (this time based on the ppLayoutChart layout), and will call the method code in Listing 9 to construct the line chart. Again, similar to the pie chart described in Tip 8, the code builds a chart image based on a chart type and source data.

Tip 11: Setting Animations and Slide Transitions
Of course, no fancy PowerPoint presentation is complete without some type of slide transition. The code below shows a method that sets a slide-by-slide transition of vertical blinds.

Public Sub SetSlideTransitions() ' Basic demonstration of looping through the slideshow collection ' use this as a guide to change settings at the slide level For Each oSlide As PowerPoint.Slide In Me.oPPTApp.ActivePresentation.Slides oSlide.SlideShowTransition.EntryEffect = _ PowerPoint.PpEntryEffect.ppEffectBlindsVertical Next End Sub

 
Figure 6: Using IntelliSense in Visual Studio 2005.
PowerPoint offers a number of slide transitions and animation schemes—the preceding code is just one brief example. Figure 6 illustrates the value of IntelliSense to view the different available options.

The value of the code in this tip isn't so much the specific result as much as it is a basic demonstration of iterating through a collection of PowerPoint objects.

Tip 12: Defining Slide Footer Information
GenPPT provides a method called BuildFooter (see Listing 10), so that a developer can define footer text for each slide. The method uses the ActivePresentation.SlideMaster.HeaderFooters object hierarchy.

Tip 13: Saving the Presentation
Finally, GenPPT provides a simple method to save a presentation:

oPPT.SavePresentation("c:\\KCCHIEFS.PPT");

The method code for SavePresentation is just as simple:



Public Sub SavePresentation(ByVal PPTName As String) Me.oPPTApp.ActivePresentation.SaveAs(PPTName) End Sub

Recommended Reading:
An excellent book on the subject of Office Automation is Microsoft Office Automation with Visual FoxPro, by Tamar Granor and Della Martin. This is an outstanding reference with many "how-to" examples. Even if you don't use Visual FoxPro, you can still apply the information in this text to different development languages.

The Baker's Dozen Commentary:
Until recently, almost all of my development efforts have been in C#. For many projects, C# will continue to be my language of choice. Having said that, I've gained some insight into the value of VB, especially when using Visual Studio 2005. The productivity enhancements in the development environment helped me tremendously in building GenPPT.

Closing Thoughts
GenPPT serves as a set of starter classes to help developers with PowerPoint automation. As I look back, there are many opportunities for improvement.

  • You could replace the references to specific shape objects ("Rectangle 2") with something more elegant, such as reading through a shape collection.
  • You could replace all the different methods for creating charts with one generic method that uses a chart type as a parameter.
  • You might prefer to pass objects instead of datasets.
  • You could define fonts and colors as parameters to further customize the display of the output
Finally, there are several places where additional enumerations would improve the readability of the code.

While I'll continue to modify this project, I encourage people to dive in and take a stab at some of these, or others. Fortunately, end users are never locked into the generated output: they can always modify the output slides.



Kevin S. Goff is the founder and principal consultant of Common Ground Solutions, a consulting group that provides custom web and desktop software solutions in .NET, Visual FoxPro, SQL Server, and Crystal Reports. Kevin has been building software applications for 17 years. He has received several awards from the U.S. Department of Agriculture for systems automation. He has also received special citations from Fortune 500 companies for solutions that yielded six-figure returns on investment. He has worked in such industries as insurance, accounting, public health, real estate, publishing, advertising, manufacturing, finance, consumer packaged goods, and trade promotion. In addition, Kevin provides many forms of custom training.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date