+

PHP Spreadsheet_Excel_Writer | SetColor () Function

Syntax:
void Format::setColor (mixed $color)
Parameters: This function takes one parameter as $color, which takes a string color value, such as "green", or a value between 0 and 64.Returned value:this function returns TRUE on success and PEAR_ERROR on error.Example 1:  
// require_once & # 39 ; Spreadsheet / Excel / Writer.php & # 39 ;; 
// Create Spreadsheet_Excel_Writer object $workbook  = new Spreadsheet_Excel_Writer ( );  
// Add sheet $worksheet = & amp; $workbook -> addWorksheet ( ` SetColor` ); for ( $inc = 0; $inc < 64; $inc ++) { // Sets the color of the cell content $format = $workbook -> addFormat(); $format -> setColor ( $inc ); $worksheet -> write ( $inc , 0, `Color (index` . $inc . ` ) ` , $format ); }  
// Send file to browser $workbook -> send ( `setColor.xls` );  
// Close the workbook $workbook -> close(); ?>
Output: Example 2: < tbody> require_once `Spreadsheet / Excel / Writer.php` ;  
// Create a Spreadsheet_Excel_Writer object $workbook  = new Spreadsheet_Excel_Writer();  
// Add sheet $worksheet = & amp; $workbook -> addWorksheet ( ` SetColor` );  
// Sets the color of the cell content $format = $workbook -> addFormat();  
// Set the color for the text $format -> setColor (17);  
// Set the text size $format -> setSize (25);  
// Add text to Excel $worksheet -> write (0, 5, `GeeksForGeeks` , $format );  
// Sets the color of the cell content $format1 = $workbook -> addFormat();  
// Set the color for the cell $format1 -> setColor (2);  
// Set the text size $format1 -> setSize (20);  
// Add text to Excel sheet $worksheet -> write (2, 5, `sarthak_ishu11` , $format1 );  
// Send file to browser $workbook -> send ( `test.xls` );  
// Close the workbook $workbook -> close(); ?>
Output: Link : https:// pear .php.net / manual / en / package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setcolor.php
Get Solution for free from DataCamp guru