Keep chart/graph style

南楼画角 提交于 2021-02-10 11:27:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!