You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 04:50:05