setColor()函數是PHP中的內置函數| Spreadsheet_Excel_Writer用於設置單元格內容的顏色。
用法:
void Format::setColor( mixed $color )
參數:此函數接受單個參數$color,該參數將顏色值作為字符串(例如“ green”)或0到64之間的值。
返回值:成功時返回TRUE,失敗時返回PEAR_ERROR。
範例1:
<?php
// require_once 'Spreadsheet/Excel/Writer.php';
// Create Spreadsheet_Excel_Writer Object
$workbook = new Spreadsheet_Excel_Writer();
// Add worksheet
$worksheet = &$workbook->addWorksheet('SetColor');
for ($inc = 0; $inc < 64; $inc++) {
// Sets the color of a cell's content
$format = $workbook->addFormat();
$format->setColor($inc);
$worksheet->write($inc, 0, 'Color (index '.$inc.')', $format);
}
// Send file to browser
$workbook->send('setColor.xls');
// Close workbook
$workbook->close();
?>
輸出:
範例2:
<?php
require_once 'Spreadsheet/Excel/Writer.php';
// Create Spreadsheet_Excel_Writer Object
$workbook = new Spreadsheet_Excel_Writer();
// Add worksheet
$worksheet = &$workbook->addWorksheet('SetColor');
// Sets the color of a cell's content
$format = $workbook->addFormat();
// Set color to the text
$format->setColor(17);
// Set the size of text
$format->setSize(25);
// Add text to the excel
$worksheet->write(0, 5, 'GeeksForGeeks', $format);
// Sets the color of a cell's content
$format1 = $workbook->addFormat();
// Set color to the cell
$format1->setColor(2);
// Set the size of the text
$format1->setSize(20);
// Add text to the excel sheet
$worksheet->write(2, 5, 'sarthak_ishu11', $format1);
// Send file to browser
$workbook->send('test.xls');
// Close workbook
$workbook->close();
?>
輸出:
相關用法
- PHP GmagickPixel setcolor()用法及代碼示例
- PHP ImagickPixel setColor()用法及代碼示例
- p5.js int()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP tan( )用法及代碼示例
- p5.js hex()用法及代碼示例
- p5.js str()用法及代碼示例
- PHP end()用法及代碼示例
- p5.js arc()用法及代碼示例
- p5.js cos()用法及代碼示例
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 PHP | Spreadsheet_Excel_Writer | setColor() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。