Blogger Information
Blog 51
fans 0
comment 1
visits 65295
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php合并多个word文件
鱼的熊掌
Original
1554 people have browsed it

tbszip下载


  1. include_once('extend/tbszip.php');
  2. $zip = new \clsTbsZip();
  3. $path = 'Public/File/2022/'; //docx文件所在目录
  4. $filelist=scandir($path);
  5. foreach($filelist as $ks=>$vs) {
  6. if ($vs=='.' || $vs=='..' || $vs=='.DS_Store') {
  7. continue;
  8. }
  9. $zip->Open($path.$vs);
  10. $content1 = $zip->FileRead('word/document.xml');
  11. $zip->Close();
  12. $p = strpos($content1, '<w:body');
  13. if ($p===false) exit("失败");
  14. $p = strpos($content1, '>', $p);
  15. $content1 = substr($content1, $p+1);
  16. $p = strpos($content1, '</w:body>');
  17. if ($p===false) exit("失败");
  18. $content1 = substr($content1, 0, $p);
  19. $strs='<w:p><w:pPr><w:rPr><w:sz w:val="21"/><w:szCs w:val="21"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p><w:pPr><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p/><w:p/><w:p><w:r><mc:AlternateContent>';
  20. $oldstrs='<w:p><w:pPr><w:rPr><w:sz w:val="21"/><w:szCs w:val="21"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p/><w:p><w:pPr><w:rPr><w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/></w:rPr></w:pPr></w:p><w:p/><w:p/><w:p/><w:p><w:r><mc:AlternateContent>';
  21. $content1=str_replace($strs,$oldstrs,$content1);
  22. $contents[]=$content1;
  23. }
  24. $zip->Open($path."/empty.docx"); // 空的docx文件
  25. $content2 = $zip->FileRead('word/document.xml');
  26. $p = strpos($content2, '</w:body>');
  27. if ($p===false) exit("失败");
  28. $content2 = substr_replace($content2, implode('',$contents), $p, 0);
  29. $zip->FileReplace('word/document.xml', $content2, TBSZIP_STRING);
  30. $savePath='Public/Write/merges.docx';
  31. // 合并docx文件存储地址
  32. $zip->Flush(TBSZIP_FILE,$savePath);
  33. //或者输出下载
  34. header("Cache-Control: public");
  35. header("Content-Description: File Transfer");
  36. header('Content-disposition: attachment; filename='.basename($zipfilename)); //文件名
  37. header("Content-Type: application/force-download");
  38. header("Content-Transfer-Encoding: binary");
  39. header('Content-Length: '. filesize($savePath)); //告诉浏览器,文件大小
  40. readfile($savePath);
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post