setFgColor()函数是PHP中的内置函数| Spreadsheet_Excel_Writer,用于设置电子表格单元格的前景色。为了使用此函数,请使用setPattern函数。在这里,“foreground”表示单元格背景的顶层。
用法:
void Format::setFgColor( $color )
参数:此函数接受单个参数$color,该参数将color的值作为字符串(例如“ red”,“ green”)使用,并通过在8到63之间指定颜色代码来接受另一种方法。
返回值:成功时返回TRUE,失败时返回PEAR_ERROR。
范例1:
<?php
require_once 'Spreadsheet/Excel/Writer.php';
// Create Spreadsheet Excel Writer Object
$workbook = new Spreadsheet_Excel_Writer();
// Add Worksheet to the spreadsheet
$worksheet =& $workbook->addWorksheet();
// Add "regular" green to the cell
$format_regular_green =& $workbook->addFormat();
$format_regular_green->setFgColor('green');
// Add "special" green to the cell
$format_special_green =& $workbook->addFormat();
$format_special_green->setFgColor(11);
// Set Custom Green Color
$workbook->setCustomColor(12, 10, 200, 10);
$format_our_green =& $workbook->addFormat();
$format_our_green->setFgColor(12);
// Set Column width
$worksheet->setColumn(0, 0, 30);
// Add data to the 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 the browser
$workbook->send('setFgColor.xls');
// Close the file
$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();
// Set Font Family Times New Roman
$format_setFgColor =& $workbook->addFormat();
$format_setFgColor->setFontFamily('Times New Roman');
// Set Italic Property
$format_setFgColor->setItalic();
// Set Shadow to text
$format_setFgColor->setShadow();
// Set the foreground color
$format_setFgColor->setBgColor('yellow');
// Set the pattern
$format_setFgColor->setPattern(4);
// Write to Worksheet
$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.geeksforgeeks.org/", $format_setFgColor);
$workbook->send('test.xls');
$workbook->close();
?>
输出:
相关用法
- PHP sin( )用法及代码示例
- PHP abs()用法及代码示例
- d3.js d3.map.set()用法及代码示例
- p5.js int()用法及代码示例
- p5.js str()用法及代码示例
- PHP cos( )用法及代码示例
- p5.js hex()用法及代码示例
- PHP end()用法及代码示例
- p5.js arc()用法及代码示例
- p5.js cos()用法及代码示例
- p5.js log()用法及代码示例
- p5.js red()用法及代码示例
注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 PHP | Spreadsheet_Excel_Writer | setFgColor() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。