<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>arcster.com Blog &#187; COM</title>
	<atom:link href="http://blog.arcster.com/blog/index.php/tag/com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.arcster.com</link>
	<description>These fragments I have shored against my ruins</description>
	<lastBuildDate>Sun, 11 Sep 2011 00:05:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Another day in the life of a ColdFusion drone</title>
		<link>http://blog.arcster.com/2008/02/another-day-in-the-life-of-a-coldfusion-drone/</link>
		<comments>http://blog.arcster.com/2008/02/another-day-in-the-life-of-a-coldfusion-drone/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 14:55:18 +0000</pubDate>
		<dc:creator>arcster</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[COM]]></category>

		<guid isPermaLink="false">http://arcster.com/blog/2008/02/14/another-day-in-the-life-of-a-coldfusion-drone/</guid>
		<description><![CDATA[This may be of use to the handful of people in the universe who: 1. use ColdFusion; 2. have no direct access to their Coldfusion server; 3. need to manipulate PowerPoint on the server; and 4. aren&#8217;t using .NET OK, &#8230; <a href="http://blog.arcster.com/2008/02/another-day-in-the-life-of-a-coldfusion-drone/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This may be of use to the handful of people in the universe who: 1. use ColdFusion; 2. have no direct access to their Coldfusion server; 3. need to manipulate PowerPoint on the server; and 4. aren&#8217;t using .NET</p>
<p>OK, the three of you who are still reading may continue.</p>
<p>So I&#8217;m trying to do this via COM and ColdFusion&#8217;s cfobject tag.</p>
<p>First, I waited a couple months for the people who run the server to get PowerPoint installed on the server. Then I dusted off some old code from <a title="CF Comet" href="http://www.cfregex.com/cfcomet/forum/ViewThread.cfm?ThreadID=F09104FE-1802-684D-687BF5A8897E7E1F">CF Comet</a>.</p>
<p>My code looked like this:</p>
<pre>&lt;cfobject TYPE="com" NAME="objPPT" CLASS="PowerPoint.Application" ACTION="connect"&gt;
&lt;cfobject TYPE="com" NAME="objPPT" CLASS="PowerPoint.Application" ACTION="create"&gt;

presentationsCollection = objPPT.Presentations;

myPresentation = presentationsCollection.Open("D:xxxmaingetppt.ppt", False, False, False);

newpresentation = objPresentation.SaveAS("D:xxxmainnew.ppt",11, True);
// Close a presentation

objPresentation.Close();

// Quit PowerPoint

objPPT.Quit();</pre>
<p>Here was my error the first time I ran the script. (Note: path and file names have been altered)<br />
<code>An exception occurred when executing a Com method.<br />
The cause of this exception was that: AutomationException: 0x80004005 -<br />
PowerPoint could not open the file. in 'Microsoft Office PowerPoint 2003'.</code><br />
Updated April 2009</p>
<p>Thank you Todd for noticing that somehow my posting got completely botched in the copy and paste process. Here is a working example of a ColdFusion file that uses COM to open a powerpoint pre-loaded onto the server, add data, and then save the new file into a location on the server where the user can download it</p>
<p>Also available as a <a href="http://arcster.com/blog/wp-content/uploads/2009/04/coldfusioncom.txt">text file</a></p>
<p>&lt;cfset VARIABLES.localpath = &#8220;D:\rootfolder\subfolder\&#8221;&gt;</p>
<p>&lt;cfset VARIABLES.remotepath = &#8220;http://someurl/&#8221;&gt;</p>
<p>&lt;cfset VARIABLES.pptext = &#8220;.ppt&#8221;&gt;</p>
<p>&lt;cfset VARIABLES.sourcefile = &#8220;testppt&#8221;&gt;</p>
<p>&lt;cfset VARIABLES.nowdate = tostring(DateFormat(Now(),&#8217;yyyymmdd&#8217;))&gt;</p>
<p>&lt;cfset VARIABLES.nowtime = tostring(TimeFormat(Now(),&#8217;hhmmss&#8217;))&gt;</p>
<p>&lt;cfset VARIABLES.newfile = trim(VARIABLES.nowdate) &amp; trim(VARIABLES.nowtime)&gt;</p>
<p>&lt;cfset VARIABLES.basefilepath = VARIABLES.localpath &amp; VARIABLES.sourcefile &amp; VARIABLES.pptext&gt;</p>
<p>&lt;cfset VARIABLES.newfilepath = VARIABLES.localpath &amp; VARIABLES.newfile &amp; VARIABLES.pptext&gt;</p>
<p>&lt;cfset VARIABLES.newurl = VARIABLES.remotepath &amp; VARIABLES.newfile &amp; VARIABLES.pptext&gt;</p>
<p>&lt;cfquery name=&#8221;Query&#8221; datasource=&#8221;datasource&#8221;&gt;</p>
<p>some query to populate chart</p>
<p>&lt;/cfquery&gt;</p>
<p>&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221; &#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;</p>
<p>&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=iso-8859-1&#8243; /&gt;</p>
<p>&lt;title&gt;PowerPoint Creator&lt;/title&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;cftry&gt;</p>
<p>&lt;CFOBJECT</p>
<p>TYPE=&#8221;com&#8221;</p>
<p>NAME=&#8221;objPPT&#8221;</p>
<p>CLASS=&#8221;PowerPoint.Application&#8221;</p>
<p>ACTION=&#8221;connect&#8221;&gt;</p>
<p>&lt;cfcatch&gt;</p>
<p>&lt;CFOBJECT</p>
<p>TYPE=&#8221;com&#8221;</p>
<p>NAME=&#8221;objPPT&#8221;</p>
<p>CLASS=&#8221;PowerPoint.Application&#8221;</p>
<p>ACTION=&#8221;create&#8221;&gt;</p>
<p>&lt;/cfcatch&gt;</p>
<p>&lt;/cftry&gt;</p>
<p>&lt;!&#8212;</p>
<p>kudos to</p>
<p>http://www.cfregex.com/cfcomet/forum/ViewThread.cfm?ThreadID=F09104FE-1802-684D-687BF5A8897E7E1F</p>
<p>&#8212;&gt;</p>
<p>&lt;cfset presentationsCollection = objPPT.Presentations&gt;</p>
<p>&lt;cfscript&gt;</p>
<p>//open as readonly</p>
<p>myPresentation = presentationsCollection.Open(VARIABLES.basefilepath, True, False, False);</p>
<p>//The presentation object has a slides collection</p>
<p>if (isDebugMode()) writeOutput(&#8220;Creating collection&#8221;);</p>
<p>CollSlides = myPresentation.Slides;</p>
<p>//The first param defines the number of slides.</p>
<p>//The second parameter defines the slide layout</p>
<p>//Figured out blank by trial and error</p>
<p>//blank = 12</p>
<p>//blank with title = 11</p>
<p>ObjSlide = CollSlides.Add(1, 11);</p>
<p>// This chunk of code creates a title. I know it&#8217;s a lot just to create a title, but Powerpoint has a lot of classes.</p>
<p>slideShape = ObjSlide.Shapes;</p>
<p>newShape = slideShape.Title;</p>
<p>myTextFrame = newShape.TextFrame;</p>
<p>myTextRange = myTextFrame.TextRange;</p>
<p>myTextRange.Text = &#8220;This is the Title&#8221;;</p>
<p>// This is how to add more text to the slide.</p>
<p>bodyShape = SlideShape.AddTextBox(1, 200, 300, 700, 100);</p>
<p>bodyShapeTextFrame = bodyShape.TextFrame;</p>
<p>bodyShapeTextRange = bodyShapeTextFrame.TextRange;</p>
<p>bodyShapeTextRange.Text = &#8220;This is some additional text&#8221;;</p>
<p>//add table</p>
<p>//http://skp.mvps.org/ppttable.htm</p>
<p>//AddTable(NumRows, NumColumns, Left, Top, Width, Height)</p>
<p>//</p>
<p>//Somewhere I read you couldn&#8217;t stack your arguments (this.that.theother) more than two deep</p>
<p>//This doesn&#8217;t seem to be true.</p>
<p>//</p>
<p>//Define the most rows that can display on a page</p>
<p>imaxrows = 10;</p>
<p>//How many rows returned by query?</p>
<p>irowct = Query.RecordCount;</p>
<p>//have to account for record count of 0, or we&#8217;ll have issues</p>
<p>//note the nify use of integer division and mod</p>
<p>if (irowct GT imaxrows)</p>
<p>inumslides = funcnumslides(irowct, imaxrows);</p>
<p>function funcnumslides(i1, i2){</p>
<p>inumint =  i1 \ i2;</p>
<p>inummod = i1 mod i2;</p>
<p>if (inummod GT 0)</p>
<p>return inumint + 1;</p>
<p>else</p>
<p>return inumint;</p>
<p>}</p>
<p>ObjSlide = CollSlides.Add(inumslides, 11);</p>
<p>bodyShape = SlideShape.AddTable(imaxrows,1,30,110,660,320);</p>
<p>oTable = bodyShape.Table;</p>
<p>oCell = oTable.Cell(1,1);</p>
<p>try {</p>
<p>otext = oCell.Shape.TextFrame.TextRange;</p>
<p>rsltText = Query.RecordCount;</p>
<p>otext.Text = rsltText;</p>
<p>}</p>
<p>catch(Any excpt)</p>
<p>{</p>
<p>WriteOutput(&#8220;#excpt.Message#&#8221;);</p>
<p>}</p>
<p>newpresentation = myPresentation.SaveAS(VARIABLES.newfilepath, 11, True);</p>
<p>// Close a presentation</p>
<p>myPresentation.Close();</p>
<p>//Quit PowerPoint</p>
<p>objPPT.Quit();</p>
<p>&lt;/cfscript&gt;</p>
<p>&lt;p&gt;Your file is ready for &lt;a href = &#8220;&lt;cfoutput&gt;#VARIABLES.newurl#&lt;/cfoutput&gt;&#8221;&gt;download&lt;/a&gt;.<br />
On opening you will be asked to allow macros. Click OK.&lt;/p&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.arcster.com/2008/02/another-day-in-the-life-of-a-coldfusion-drone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

