1,848 total views, 2 views today

Please follow these Simple & Quick Steps to Export your HTML Content to Doc in CakePHP:-

Step#1: Build the <HTML> content dynamically according to the requirement.

Step#2: Store the <HTML>content in a variable (Example: $ExportContent)

$ExportContent = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="http://www.w3.org/1999/xhtml">


<h2>Mark sheet Table</h2>

<table style="width:100%" border="1" cellspacing="0">
       <th>First Name</th>
       <th>Last Name</th>
       <td align="center">1</td> 
       <td align="right">94</td>
       <td align="center">2</td> 
       <td align="right">80</td>


Step#3: After building the content pass appropriate headers to convert this <HTML>content to Doc

header("Content-type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

Step#4: Provide file name to “Content-Disposition” header that we want to give the doc file name

header("Content-Disposition: attachment; Filename=myfile.doc");
echo $ExportContent;

Did you find above tips useful? Feel free to drop in your suggestion…

Interested in anything on CakePHP? Let’s have a quick discussion.