PhpSpreadsheet加载含图表Excel模板后保存导致文件损坏问题
问题:PhpSpreadsheet加载含图表的Excel模板直接保存后文件损坏
现象描述
加载包含两个工作表且其中一个工作表插入图表的TemplateFile.xlsx模板文件,未做任何修改直接保存为RetainedFile.xlsx后,文件出现损坏。打开文件时会收到以下提示:
我们发现‘RetainedFile.xlsx’中的某些内容存在问题。是否要尝试尽可能恢复内容?如果信任此工作簿的来源,请点击‘是’。
当前使用的PhpSpreadsheet版本为1.21.0。
复现代码
<?php require 'vendor/autoload.php'; // Include the PhpSpreadsheet autoloader use PhpOffice\PhpSpreadsheet\IOFactory; // Path file template which includes a chart $inputFileName = '.../TemplateFile.xlsx'; // Load the spreadsheet $spreadsheet = IOFactory::load($inputFileName); // Save the spreadsheet without making any changes $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); $writer->save('.../RetainedFile.xlsx'); ?>
内容的提问来源于stack exchange,提问作者ncaffrey
相关产品推荐
相关产品推荐

