Summing UpThe information contained in this chapter sets you well on your way to integrating .NET with ColdFusion. For references outside the context of this chapter regarding ColdFusion and .NET integration, go to: http://www.macromedia.com/devnet or http://msdn.microsoft.com/netframework. |
Chapter 26. Extending ColdFusion with COMIN THIS CHAPTER Understanding COM 1 Working with COM Objects in ColdFusion 2 New Techniques for Improving Performance and Reliability 13 Common Questions and Problems 25
This chapter and all the code and examples used throughout the chapter can be downloaded from the
|
Chapter 27. Integrating with Microsoft OfficeIN THIS CHAPTER Document Properties 835 Microsoft Jet 841 Apache POI 843 HTML, XML, and CSS 848 Automation 856
ColdFusion applications can integrate with Microsoft Office to provide advanced document functionality not available with traditional HTML output. Developers can take advantage of these features to provide users with editable documents, leverage features of the Office applications, import data from other applications, and produce specialized complex
|
Document Properties
Microsoft Excel, PowerPoint, and Word files are natively stored in a binary format referred to as an
OLE Compound Document
. In this hierarchical structured format, programs that understand even a small part of the hierarchy can interact with that data while ignoring the rest without fear of corrupting the document. This allows us to manipulate Microsoft Office files through ColdFusion safely and
One part of the document data associated with every OLE Compound Document, including Office files, is the Document Summary Properties. These properties are commonly known as the built-in properties users occasionally set through the Office
Figure 27.1. Manually editing the built-in summary properties in a Microsoft Word document through the user interface.
NOTE
All of the examples in this chapter use
DSOFile
to read and write document properties.
DSOFile
is a COM object and thus these examples are
http://www.microsoft.com/downloads/details.aspx?familyid=9ba6fac6-520b-4a0a-878a-53ec8300c4c2. Review Listing 27.1 for an example of reading Document Properties. This example lists all of the files in a directory along with their author. Listing 27.1. ListAuthors.cfm List Files with Authors Using Summary Properties
<!---
Filename: ListAuthors.cfm
Purpose: List files in a directory along with the author property.
Depends on: DSOFile COM object installed on server.
--->
<!--- get a list of files in the target directory --->
<cfset dir=ExpandPath("files")>
<cfdirectory
action="list"
directory="#dir#"
name="files">
<!--- Instantiate a Document Properties object --->
<cfobject
action="create"
type="com"
class="DSOFile.OleDocumentProperties"
name="props">
<!--- display headings for our table --->
<h1>Directory Listing with Author</h1>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>File</th>
<th>Modified</th>
<th>Author</th>
</tr>
<!--- loop through files and read their summary properties --->
<cfoutput query="files">
<cfset props.Open(dir & "/" & files.name)>
<cfset summary = props.SummaryProperties>
<!--- display data from cfdirectory and the property reader --->
<tr>
<td>#files.name#</td>
<td>#DateFormat(files.dateLastModified)#</td>
<td>#summary.author#</td>
</tr>
<!--- we're done with this file --->
<cfset props.Close()>
</cfoutput>
</table>
<!--- we're done with the reader, release it --->
<cfset ReleaseComObject(props)>
This example starts with a standard directory listing and includes information provided by ColdFusionthe filename and the last modified date. In addition, it instantiates a
DSOFile.OleDocumentProperties
object that is used to read the properties of each file in order to display the author. To accomplish this, the
PropertyReader
provides an
Open
method and then a
SummaryProperties
object, which in
Table 27.1. Partial List of Properties in the SummaryProperties Object
Figure 27.2. Output from
ListAuthors.cfm
the files along with author
|