First Attempt At Excel Document Formatting Hooks Using ColdFusion And POI

<!---
	Let's start out by creating an array of arrays that will
	act as the data for our Excel sheet. Behind the scenes,
	this array is actually getting converted to a query (but
	that is not important at this time).
--->
<cfset arrData = ArrayNew( 1 ) />
<cfset arrData[ 1 ] = ListToArray( "Azure,9.0,10.0,Brunette" ) />
<cfset arrData[ 2 ] = ListToArray( "Sarah,9.0,9.0,Brunette" ) />
<cfset arrData[ 3 ] = ListToArray( "Kit,7.0,7.0,Brunette" ) />
<cfset arrData[ 4 ] = ListToArray( "Kim,8.0,n/a,Black" ) />
<cfset arrData[ 5 ] = ListToArray( "Annie,7.0,9.0,Brunette" ) />
<cfset arrData[ 6 ] = ListToArray( "India,6.0,5.0,Blonde" ) />
<cfset arrData[ 7 ] = ListToArray( "Cici,5.0,3.0,Blonde" ) />
 
 
<!---
	Now, let's create an instance of the POI Utility. This call
	assumes that the POIUtility.cfc is in the same directory as
	the calling code.
--->
<cfset objPOI = CreateObject(
	"component",
	"POIUtility"
	).Init()
	/>
 
 
<!---
	Get a POI Sheet object from the POI Utility. The sheet
	object is in now way tied to the POI Utility. This is
	just a comvenience method. You could just have easily
	called the CreateObject() method and instantiated the
	sheet yourself.... that is why CreateSheet() returns
	an uninitialized sheet (so that you can pass in the
	good stuff).
 
	When initializing, we can pass in the Name of the sheet,
	the data array we created above, the column names (for
	the header row) and the default CSS information).
--->
<cfset objSheet = objPOI.CreateSheet().Init(
	Name = "Hot Chicks",
	DataArray = arrData,
	ColumnNames = "Name,Hotness,Coolness,Hair Color",
	HeaderCSS = "font: italic 16pt verdana ; background: lime ; color: white ; border-bottom: 3px solid green ;",
	RowCSS = "border-bottom: 1px solid gold ; font-size: 12pt ;",
	AltRowCSS = "background-color: lemon_chiffon ;"
	) />
 
 
<!---
	Now, here's where it gets exciting. Let's format cells in
	the Excel file using conditions and CSS.
--->
 
 
<!---
	Here, we are are going to find any cell whose value is
	"n/a" and update the CSS with font and color.
--->
<cfset objSheet.AddFormatting(
	Condition = "{value} EQ 'n/a'",
	CSS = "font-style: italic ; color: GREY_40_PERCENT ;"
	) />
 
<!---
	Here, we are going to find any value in the 2nd column
	whose value is greater than or equal to 9 and we are
	going to update the CSS with color and font.
--->
<cfset objSheet.AddFormatting(
	Condition = "({column} EQ 2) AND (Val( {value} ) GTE 9)",
	CSS = "color: red ; font-weight: bold ;"
	) />
 
<!---
	Here, wer are going ot find any value in the 3rd column
	whose value is greater than or equal to 9 and update
	the CSS with color.
--->
<cfset objSheet.AddFormatting(
	Condition = "({column} EQ 3) AND (Val( {value} ) GTE 9)",
	CSS = "color: red ;"
	) />
 
 
<!---
	Now that our data and formatting are set, we are going to
	write the Excel file by sending in the file path and the
	sheet object we created above.
--->
<cfset objPOI.WriteExcel(
	FilePath = ExpandPath( "./test.xls" ),
	Sheets = objSheet
	) />

For Cut-and-Paste