Skip to content

Commit

Permalink
Provide a list of all predefined colours available to formatting meth…
Browse files Browse the repository at this point in the history
…ods. Fixes #179
  • Loading branch information
cfsimplicity committed Mar 6, 2020
1 parent 65896c3 commit a097135
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ You will probably want to place the spreadsheet library files in a central locat
* [getCellType](https://github.com/cfsimplicity/lucee-spreadsheet/wiki/getCellType)
* [getColumnWidth](https://github.com/cfsimplicity/lucee-spreadsheet/wiki/getColumnWidth)
* [getColumnWidthInPixels](https://github.com/cfsimplicity/lucee-spreadsheet/wiki/getColumnWidthInPixels)
* [getPresetColorNames](https://github.com/cfsimplicity/lucee-spreadsheet/wiki/getPresetColorNames)
* [getRowCount](https://github.com/cfsimplicity/lucee-spreadsheet/wiki/getRowCount)
* [hideColumn](https://github.com/cfsimplicity/lucee-spreadsheet/wiki/hideColumn)
* [hideRow](https://github.com/cfsimplicity/lucee-spreadsheet/wiki/hideRow)
Expand Down
11 changes: 10 additions & 1 deletion Spreadsheet.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,15 @@ component{
return result;
}

public array function getPresetColorNames(){
var presetEnum = loadClass( "org.apache.poi.hssf.util.HSSFColor$HSSFColorPredefined" )[ "BLUE" ];
var result = [];
for( var value in presetEnum.values() )
result.Append( value.name() );
result.Sort( "text" );//ACF2016 (not 2018) returns "YES" from a sort instead of the sorted array, so perform sort separately.
return result;
}

public numeric function getRowCount( required workbook, sheetNameOrNumber ){
if( arguments.KeyExists( "sheetNameOrNumber" ) ){
if( IsValid( "integer", arguments.sheetNameOrNumber ) AND IsNumeric( arguments.sheetNameOrNumber ) )
Expand Down Expand Up @@ -2996,7 +3005,7 @@ component{
return color.getIndex();
}
catch( any exception ){
Throw( type=exceptionType, message="Invalid Color", detail="The color provided (#arguments.colorName#) is not valid." );
Throw( type=exceptionType, message="Invalid Color", detail="The color provided (#arguments.colorName#) is not valid. Use getPresetColorNames() for a list of valid color names" );
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/specs/getPresetColorNames.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<cfscript>
describe( "getPresetColorNames", function(){
it( "returns an alphabetical array of preset color names available for use in color formatting options", function() {
expect( s.getPresetColorNames() ).toHaveLength( 48 );
expect( s.getPresetColorNames()[ 1 ] ).toBe( "AQUA" );
expect( s.getPresetColorNames()[ 48 ] ).toBe( "YELLOW" );
});
});
</cfscript>

0 comments on commit a097135

Please sign in to comment.