简体   繁体   English

自定义图表 PhpSpreadSheet

[英]Custom chart PhpSpreadSheet

I'm trying to set the color of the columns and the font size of an Excel chart created by phpSpreadsheet.我正在尝试设置列的颜色和由 phpSpreadsheet 创建的 Excel 图表的字体大小。

There isn't documentation about how to change it and There isn't any function.没有关于如何更改它的文档,也没有任何功能。

For color cell:对于颜色单元格:

cell by cell逐个细胞

$spreadsheet->getActiveSheet()->getStyle($cells)->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('ffffff');

range of cells单元格范围

$spreadsheet->getActiveSheet()->getStyle('A1:A5')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('ffffff');

Font for cell:单元格字体:

$objPHPExcel->getActiveSheet()->getStyle("A9")->getFont()->setSize(11);

Chart ex:图表示例:

// Custom colors for dataSeries (gray, blue, red, orange)
 $colors = [
'cccccc', '00abb8', 'b8292f', 'eb8500',
 ];
// Set the Data values for each data series we want to plot
//     Datatype
//     Cell reference for data
//     Format Code
//     Number of datapoints in series
//     Data values
//     Data Marker
//     Custom colors
$dataSeriesValues1 = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 
'Worksheet!$C$2:$C$5', null, 4, [], null, $colors),
 ];
 $dataSeriesValues2Element->setFillColor($colors);

All code here: Official Guide所有代码在这里: 官方指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM