PHP | Spreadsheet_Excel_Writer | setColor() Function
Last Updated :
21 Dec, 2018
The setColor() function is an inbuilt function in PHP | Spreadsheet_Excel_Writer which is used to set the color of a cell content.
Syntax:
void Format::setColor( mixed $color )
Parameters: This function accepts single parameter as $color which takes value of color as string like ‘green’ or value from 0 to 64.
Return Value: This function returns TRUE on success and PEAR_ERROR on failure.
Example 1:
<?php
$workbook = new Spreadsheet_Excel_Writer();
$worksheet = & $workbook ->addWorksheet( 'SetColor' );
for ( $inc = 0; $inc < 64; $inc ++) {
$format = $workbook ->addFormat();
$format ->setColor( $inc );
$worksheet ->write( $inc , 0, 'Color (index ' . $inc . ')' , $format );
}
$workbook ->send( 'setColor.xls' );
$workbook ->close();
?>
|
Output:
Example 2:
<?php
require_once 'Spreadsheet/Excel/Writer.php' ;
$workbook = new Spreadsheet_Excel_Writer();
$worksheet = & $workbook ->addWorksheet( 'SetColor' );
$format = $workbook ->addFormat();
$format ->setColor(17);
$format ->setSize(25);
$worksheet ->write(0, 5, 'GeeksForGeeks' , $format );
$format1 = $workbook ->addFormat();
$format1 ->setColor(2);
$format1 ->setSize(20);
$worksheet ->write(2, 5, 'sarthak_ishu11' , $format1 );
$workbook ->send( 'test.xls' );
$workbook ->close();
?>
|
Output:
Reference: https://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setcolor.php
Share your thoughts in the comments
Please Login to comment...