PhpSpreadsheet 保存并保持样式

PhpSpreadsheet save and keep style

我用PhpSpreadsheet读写了一个Excel文件,我想保存文件的样式(图片、字体样式、颜色等)。

我在PhpSpreadsheet的文档中没有找到方法

我可以只保存数据而不是所有样式:

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load("myFile.xls");

// Code ...

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('mySavedFile.xls');

如何保存带有样式的文件?

我找到了解决方法,很简单!我只是删除了这个:$reader->setReadDataOnly(true);

代码:

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
// $reader->setReadDataOnly(true);
$spreadsheet = $reader->load("myFile.xls");

// Code ...

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('mySavedFile.xls');