问题
Is it possible to keep the chart style (shape styles) from a xlsx file when I read and write it? With my code below the style is lost .
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx AS WXlsx;
use PhpOffice\PhpSpreadsheet\Chart\Chart;
use PhpOffice\PhpSpreadsheet\Settings;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
echo "Opening file...<br>";
$spreadsheet = new Xlsx();
$spreadsheet->setIncludeCharts(true);
$spreadsheet = $spreadsheet->load("test.xlsx");
echo "Saving file...<br>";
$fileName = "testKeepChart.xlsx";
$writer = new WXlsx($spreadsheet);
$writer->setIncludeCharts(true);
$writer->setPreCalculateFormulas(false);
$writer->save($fileName);
echo "File saved as $fileName.\n";
回答1:
When using excel like templates (from existing files), charts won't load. Issue reported here, though probably won't be fixed.
来源:https://stackoverflow.com/questions/48165358/keep-chart-graph-style