Quick Steps To Export HTML Content To Doc In CakePHP

Quick Steps To Export HTML Content To Doc In CakePHP
Social sharing

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 = '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;h2&gt;Mark sheet Table&lt;/h2&gt;

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

&lt;/body&gt;
&lt;/html&gt;
';

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.

Summary
Quick Steps To Export HTML Content To Doc In CakePHP
Article Name
Quick Steps To Export HTML Content To Doc In CakePHP
Description
Here is simple & quick steps to export your HTML Content to Doc in CakePHP. Subscribe to our Blog to receive more tips on your Inbox.
Author
Publisher Name
Andolasoft
Publisher Logo

Your recently viewed posts:

    Contact Us

    We’d love to help & work with you




    When do you want to start ?


    Enter your email address to stay up to date with the latest news.
    Holler Box

    Orange Exit pop up

    Subscribe for the latest
    trends in web and
    mobile app development
    Holler Box

    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