当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


PHP Spreadsheet_Excel_Writer setColor()用法及代码示例


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(); 
?>

输出:

参考: https://pear.php.net/manual/en/package.fileformats.spreadsheet-excel-writer.spreadsheet-excel-writer-format.setcolor.php



相关用法


注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 PHP | Spreadsheet_Excel_Writer | setColor() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。