Forum Moderators: coopster

Message Too Old, No Replies

export to MS Word

problems w/ saving document and default "web layout"

         

dreeves

5:59 pm on May 21, 2010 (gmt 0)

10+ Year Member



I am writing (w/o COM) a table to MS Word very simply using a few headers and an HTML table. When it opens in MS Word, the default view is "Web Layout" (I'd like it to be "Print Layout"). Also, when I go to save the document, by default it wants to save it as an html document. Is there a way that I can tell MS Word to treat it like a normal document and 1.) display it in Print Layout and 2.) save as a .doc by default?
Changing settings within MS Word does not seem to help.

Basically, it is this:

<?php
$vWordFileName="export". ".doc";
header("Content-type: application/x-ms-download");
header("Content-Disposition: attachment; filename=$vWordFileName");
header('Cache-Control: public');
?>
<HTML>
<BODY>
<TABLE>
contentcontentcontent
</TABLE>
</BODY>
</HTML>


Thanks

redhatlab

5:05 pm on May 29, 2010 (gmt 0)

10+ Year Member



Hi,

Have your try googling for "php create a word doc"

I found a couple of code samples:

Stackoverflow
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");

echo "<html>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo "<body>";
echo "<b>My first document</b>";
echo "</body>";
echo "</html>";


Webmasters Help
<?
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=test.doc");

$fp = fopen("nicon.doc", 'w+');
$str = "<B>This is the text for the word file created through php programming</B>";

fwrite($fp, $str);

fclose($fp);
?>