Created — forked from DominicWatson/gist:1211688

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Some code to make color customization in ColdFusion 9's cfspreadsheet implementation clean

View gist:2587154
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
<cfscript>
void function spreadsheetSetCustomPalette(required any workbook, required struct palette){
var customPalette = arguments.workbook.getworkbook().getcustompalette();
var color = "";
var colorIndex = 0;
var rgb = "";
for(color in palette){
try{
colorIndex = CreateObject("java", "org.apache.poi.hssf.util.HSSFColor$#UCase( color )#").GetIndex();
} catch(any e){
throw("badColor", "The color, '#color#', was not found in the org.apache.poi.hssf.util.HSSFColor palette");
}
try{
rgb = hexToRGBByteValues(palette[color]);
} catch(any e){
throw("badColor", "The color, '#palette[color]#', is not a valid hex color");
}
customPalette.setcoloratindex(colorIndex, rgb.r, rgb.g, rgb.b);
}
}
string function hexToRGBByteValues( required string hexColor ) {
var hex = Replace(arguments.hexColor, '##', '', 'ALL');
var rgb = {};
var rgbList = "";
var i = 0;
for (i=1; i lte 5; i=i+2){
rgbList = listAppend(rgbList, InputBaseN(mid(hex,i,2),16));
}
rgb.R = javacast("int", ListGetAt(rgbList, 1)).bytevalue();
rgb.G = javacast("int", ListGetAt(rgbList, 2)).bytevalue();
rgb.B = javacast("int", ListGetAt(rgbList, 3)).bytevalue();
return rgb;
}
string function exampleUsage(){
var workBook = SpreadsheetNew();
spreadsheetSetCustomPalette( workbook, {white="000000", black="FFFFFF", lemon_chiffon="FF0000"} );
// carry on with your workbook as normal, the colors above will be substituted...
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.