如何在php中使用str_replace()函数replaceexcel文件占位符?

下面的PHP代码完全适用于word文档(特定的.docx ),但对于excel( .xlsx ),它不会改变占位符。 据我所知,这个代码将word文件转换成document.xml文件,并将zip文件的word文件夹内的文件转换成{{placeholder}}并将其更改为我们想要的文本。

if(isset($_POST["e_submit"])) { $name=(string) $_POST["e_name"]; $email=(string) $_POST["e_email"]; $source='TemplateSimpleText.docx'; $temp='template'.'.docx'; copy($source,$temp); $zip = new ZipArchive; $fileXml='word/document.xml'; if($zip->open($temp) === TRUE) { $old=$zip->getFromName($fileXml); $new=str_replace('{{Name}}',$name,$old); $new=str_replace('{{Email}}',$email,$new); $zip->deleteName($fileXml); $zip->addFromString($fileXml,$new); $zip->close(); if (ob_get_level()) { ob_end_clean(); } header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($temp)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($temp)); readfile($temp); unlink($temp); exit(); } }