Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

COM and CORBA Objects

Retrieving Built In Properties from MS Office Documents by Glowball
Posted: 23 Aug 04 (Edited 30 Sep 04)

Microsoft Office documents have meta information associated with them and you can use ColdFusion and COM to retrieve that information.  You can view this information in an Office product by going to File | Properties.  This example puts all of the properties and their values in a structure for one Office document (Word).


<!--- Set this variable to the full path of your file --->
<cfset thisFile = "C:\test.doc">

<!--- ------------------------------- --->

<!--- Get the file's extension --->
<cfset fileExt = LCase(ListLast(Trim(thisFile), "."))>

<!--- Get the correct class based on the file's extension --->
<cfif VARIABLES.fileExt IS "doc" OR VARIABLES.fileExt IS "dot" OR VARIABLES.fileExt IS "rtf">
    <cfset thisClass = "Word.Application">
<cfelseif VARIABLES.fileExt IS "xls">
    <cfset thisClass = "Excel.Application">
<cfelseif VARIABLES.fileExt IS "ppt">
    <cfset thisClass = "PowerPoint.Application">

<!--- If necessary, create the COM object and put it in the Application scope --->
    <!--- First try to connect to an existing object --->
    <cfobject type="COM" name="fileObj" class="#thisClass#" action="CONNECT">
    <!--- There is no existing object, create one --->
    <cfobject type="COM" name="fileObj" class="#thisClass#" action="CREATE">

<!--- Work in the COM object to get the properties --->
<cfif VARIABLES.fileExt IS "doc" OR VARIABLES.fileExt IS "dot" OR VARIABLES.fileExt IS "rtf">
    <cfset docs = fileObj.Documents()>
<cfelseif VARIABLES.fileExt IS "xls">
    <cfset docs = fileObj.WorkBooks()>
<cfelseif VARIABLES.fileExt IS "ppt">
    <cfset docs = fileObj.Presentations()>
<!--- Open the document --->
<cflock timeout="20" name="openDoc" type="READONLY">
    <cfset objNewDoc = docs.open(thisFile)>
<!--- Make this one the active application --->
<cfset activeApp = objNewDoc.Application>
<!--- Make this one the active document --->
<cfif VARIABLES.fileExt IS "doc" OR VARIABLES.fileExt IS "dot" OR VARIABLES.fileExt IS "rtf">
    <cfset activeDoc = fileObj.ActiveDocument>   
<cfelseif VARIABLES.fileExt IS "xls">
    <cfset activeDoc = fileObj.ActiveWorkbook>   
<cfelseif VARIABLES.fileExt IS "ppt">
    <cfset activeDoc = fileObj.ActivePresentation>   
<!--- Get the built in properties --->
<cfset docProps = activeDoc.BuiltInDocumentProperties>    

<!--- Create a structure to hold the property/value pairs --->
<cfset sProperties = StructNew()>
<!--- Loop through the properties and add them to the structure --->
<cfloop collection="#docProps#" item="property">          
    <cfset thisPropName = property.name>     
    <!--- If a value is not defined it errors out, so try/catch it --->     
        <cfset thisPropValue = property.Value>     
        <cfset thisPropValue = "">     
    <!--- Add it to the structure --->     
    <cfscript>StructInsert(sProperties, thisPropName, thisPropValue);</cfscript>

<!--- Shut down the application --->
    <cfset fileObj.Quit(0)>
    <!--- Sometimes it doesn't work, but only rarely --->

Back to Adobe FAQ Index
Back to Adobe Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close