cfExcelProxy - Returning Available Styles
As part of the ongoing rewrite of my Coldfusion wrapper cfc for Apache's POI HSSF object, I'm constantly looking into ways of adding more and more functionality. One of the limitations I had struck with my previous iteration was using already available styles from an existing workbook. Let's imagine, for a second, that you carefully take the time to create a basic template in Excel for your reporting. You take all necessary precautions to ensure that the logo is placed appropriately and the colors match with your site's layout. When you read in that template to add in data, how do you set the new cells' format to match with the template?
The main problem here is that Excel doesn't explicitly give a name to it's styles, so there aren't any easy ways to find the one we want. However, using the workbook's getNumCellStyles and getCellStyleAt methods we can retrieve the list of all available styles to the workbook:
<cfset locals.style=variables.instance.workbook.getCellStyleAt( locals.i ) />
</cfloop>
The workbook's getCellStyleAt method returns a reference to the actual style class. Once we have this, we can call all available methods to extract that styles particular attributes. I'm currently building a method, getClasses, that'll return an array of all available styles with their attributes (font name, font size, color, background (fill) color, borders, etc.). Although this is nice, as it provides all the details that one might ask for, do you see the need to have a visual method as well? Let me explain myself. Would it be worth it to have a method that returns a formatted HTML string that'll display the classes with an example cell for each, with font, color and borders applied?
Edit: Forgot to post a link to the project page.


If for no other reason that it might make any potential developer documentation easier to generate (assuming that that is a valid need in your case).
I've added a drawClasses method, and added a link to the project page in the entry.