PHP |电子表格_Excel_Writer | setColor()函数
setColor()函数是PHP中的内置函数| Spreadsheet_Excel_Writer 用于设置单元格内容的颜色。
句法:
void Format::setColor( mixed $color )
参数:此函数接受单个参数作为$color ,它将颜色的值作为字符串,如 'green' 或从 0 到 64 的值。
返回值:此函数在成功时返回 TRUE,在失败时返回 PEAR_ERROR。
示例 1:
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:
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();
?>
输出:
参考: https://pear。 PHP.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setcolor。 PHP