4 Quick Steps to Export HTML Content to Doc in CakePHP

4 Quick Steps to Export HTML Content to Doc in CakePHP

HTML Content to Doc
< 1 Minute Read

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)

[code language=”html”]
$ExportContent = ‘<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

<body>

<h2>Mark sheet Table</h2>

<table style="width:100%" border="1" cellspacing="0">
<tbody><tr>
<th>Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Points</th>
</tr>
<tr>
<td align="center">1</td>
<td>Eve</td>
<td>Jackson</td>
<td align="right">94</td>
</tr>
<tr>
<td align="center">2</td>
<td>John</td>
<td>Doe</td>
<td align="right">80</td>
</tr>
</tbody></table>

</body>
</html>
‘;
[/code]

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

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

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

[code language=”html”]
header("Content-Disposition: attachment; Filename=myfile.doc");
echo $ExportContent;
[/code]

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

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

Tags:
, ,
Jyoti
Jyotibhusan Roul
jyoti@andolasoft.com

A Product Specialist, Opensource & SaaS expert for Startups and Enterprise needs. Revenue growth strategist, Market Analyst including Leadership and Mentoring - A proud husband and father!

No Comments

Post A Comment

Exit pop up

Sad to see you leaving early...

From "Aha" to "Oh shit" we are sharing everything on our journey.
Enter your email address to stay up to date with the latest news.
Holler Box