Sunday, August 23, 2009

Dynamic Power Point presentation using ColdFusion

The below code snippets will show you how you can generate a dynamic power point using ColdFusion 9.
This is the start of the code:

<cfpresentation format="ppt" destination="f:\test\a.ppt" title="" overwrite="yes">
The code for the first slide:

<cfpresentationslide>
<html>
<body background="file:///f:/temp/bg1.jpg">
<h1 style="color:YELLOW"> This is pure HTML page </h1>
<h2 style="color:RED"> Sub title </h2>
<ul>
<li> test 1 </li>
<li> test 2 </li>
<li> test 3 </li>
</ul>
</body>
</html>
</cfpresentationslide>
The code for the second slide. This is a dynamic slide having a chart generated from a database:

<cfpresentationslide>
<cfquery name="GetSalaries" datasource="cfdocexamples">
SELECT Departmt.Dept_Name,
Employee.Dept_ID,
Employee.Salary
FROM Departmt, Employee
WHERE Departmt.Dept_ID = Employee.Dept_ID
</cfquery>

<cfquery dbtype = "query" name = "DataTable">
SELECT
Dept_Name,
AVG(Salary) AS avgSal,
SUM(Salary) AS sumSal
FROM GetSalaries
GROUP BY Dept_Name
</cfquery>

<!--- Reformat the generated numbers to show only thousands. --->
<cfloop index = "i" from = "1" to = "##DataTable.RecordCount##">
<cfset DataTable.sumSal[i] = Round(DataTable.sumSal[i]/1000)*1000>
<cfset DataTable.avgSal[i] = Round(DataTable.avgSal[i]/1000)*1000>
</cfloop>

<!--- Bar graph, from Query of Queries --->
<cfchart format="jpg"
xaxistitle="Department"
yaxistitle="Salary Average">

<cfchartseries type="bar"
query="DataTable"
itemcolumn="Dept_Name"
valuecolumn="avgSal">

<cfchartdata item="Facilities" value="35000">

</cfchartseries>
</cfchart>
</cfpresentationslide>
The code for the third slide. This shows an example of text formatting using HTML:

<cfpresentationslide >
<html>
<body style="color:GREEN" >

<h4 style="color:BLUE"> Some examples of HTML text formatting</h4>
<p><b>This text is bold</b></p>
<p><strong>This text is strong</strong></p>
<p><big>This text is big</big></p>
<p><em>This text is emphasized</em></p>
<p><i>This text is italic</i></p>
<p><small>This text is small</small></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
</body>
</html>
</cfpresentationslide>
Close the slides:

</cfpresentation>
The generated first slide:
The generated second slide:

The generated third slide:

No comments:

Post a Comment