ivan.depi
ivan.depi

Reputation: 123

Custom chart PhpSpreadSheet

I'm trying to set the color of the columns and the font size of an Excel chart created by phpSpreadsheet.

There isn't documentation about how to change it and There isn't any function.

Upvotes: 1

Views: 2466

Answers (1)

Simone Rossaini
Simone Rossaini

Reputation: 8162

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

Upvotes: 1

Related Questions