CakePHP – Export data to a .docx file

CakePHP – Export data to a .docx file

Very simple. Just copy below code and paste.

header(“Expires: Mon, 26 Jul 2020 05:00:00 GMT”);
header(“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”);
header(“Cache-Control: no-store, no-cache, must-revalidate”);
header(“Cache-Control: post-check=0, pre-check=0”, false);
header(“Pragma: no-cache”);

header(“Content-Type: application/msword; charset=ISO-8859-1”);
header(“Content-Disposition: attachment; filename=\””.<your file name>.”.doc”);

echo “<html><head><title> Cakephp  docx file</title><body>”;

echo “<your html code here>”;
echo “</body></html>”;

Hope it will work. Have a nice day!.