PHP Spreadsheet_Excel_Writer | SetFgColor () Function

PHP

Syntax:
void Format::setFgColor ($color)
Parameters: This function takes one parameter, $color, which takes a color value as a string, such as "red", "green", and another method, specifying color codes from 8 to 63.Returned value:this function returns TRUE on success and PEAR_ERROR on error.Example 1: require_once 'Spreadsheet / Excel / Writer.php' ;  
// Create an Excel Writer Object spreadsheet $workbook = new Spreadsheet_Excel_Writer();  
// Add worksheet to spreadsheet $worksheet = & amp; $workbook -> addWorksheet();  
// Add "normal" green into a cell $format_regular_green = & amp; $workbook -> addFormat(); $format_regular_green -> setFgColor ( 'green' );  
// Add "special" green to the cell $format_special_green = & amp; $workbook -> addFormat(); $format_special_green -> setFgColor (11);  
// Set custom green $workbook -> setCustomColor (12, 10, 200, 10); $format_our_green = & amp; $workbook -> addFormat(); $format_our_green -> setFgColor (12);  
// Set column width $worksheet -> setColumn (0, 0, 30);  
// Add data to spreadsheet $worksheet -> write (0, 0, "GeeksforGeeks" , $format_regular_green ); $worksheet -> write (1, 0, "Sarthak Prajapati" , $format_special_green ); $worksheet -> write (2, 0, "sarthak_ishu11" , $format_our_green );  
// Send file to browser $workbook -> send ( 'setFgColor.xls' );  
// Close file $workbook -> close(); ?>
Output: Example 2: < tbody> require_once 'Spreadsheet / Excel / Writer.php' ;  
// Create a Spreadsheet_Excel_Writer object $workbook = new Spreadsheet_Excel_Writer();  
// Add worksheet $worksheet = & amp; $workbook -> addWorksheet();  
// Install Family Times New Roman font $format_setFgColor = & amp; $workbook -> addFormat(); $format_setFgColor -> setFontFamily ( 'Times New Roman' );  
// Set italic property $format_setFgColor -> setItalic();  
// Set text shadow $format_setFgColor -> setShadow();  
// Set foreground color $format_setFgColor -> setBgColor ( 'yellow' );  
// Set the template $format_setFgColor -> setPattern (4);  
// Save to sheet $worksheet -> write (0, 0, "Information" , $format_setFgColor ); $worksheet -> write (1, 0, "Website Name" , $format_setFgColor ); $worksheet -> write (1, 1, "Address" , $format_setFgColor ); $worksheet -> write (2, 0, "GeeksforGeeks" , $format_setFgColor ); $worksheet -> write (2, 1, " https://www.engineerforengineer.org/ " , $format_setFgColor ); $workbook -> send ( 'test.xls' ); $workbook -> close(); ?>
Output: Link : https:// pear .php.net / manual / en / package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setfgcolor.php



Get Solution for free from DataCamp guru