Jump to content

php to word


techker

Recommended Posts

Hey guys i found this script that works great for what i need ..

 

se i have this script that i did for my body (loan application)

 

now i would like to export the info in a word doc

 

<?php
$ExcelFileName="test.doc";
header("Content-type: application/x-ms-download");
header("Content-Disposition: attachment; filename=$ExcelFileName");
header('Cache-Control: public');

$content=<<<EOD

echo 'php';
whatever you want to write here
including a php script
it will be included in a string and then
go in the output for a doc file

EOD;

echo $content;
?>

 

so im trying to eco all the content in the database..

 

i tryed

all the DB connection is there..

 

ao i place this after the (echo 'php';)

while($info = mysql_fetch_array($fileLIST)){;
echo $info['PERS_F_NAME'];
};

 

i get this?

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/autosspe/public_html/admin/loan/word.php on line 21

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/224564-php-to-word/
Share on other sites

ok so i got it going with this but i need to make each echo on a diffrent line??cause now it shows all in one..

 


<?
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");
header("Pragma: no-cache");
$ID=$_GET['ID'];


require "config.php";
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
	$SelectedDB = mysql_select_db($dbname);

$ID=$_GET['ID'];

$q3 = "select * from APPLICATIONS where ID ='$ID'";
$res3 = mysql_query($q3);
$row3 = mysql_fetch_assoc($res3);

?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:word"

xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
</head>
<body>
<?
echo $row3['PERS_F_NAME'];
echo $row3['PERS_L_NAME'];
echo $row3['PERS_DATE_BIRTH'];
echo $row3['PERS_SSN'];
echo $row3['PERS_DRIVERS_L'];
echo $row3['PERS_ADD'];
echo $row3['PERS_CITY'];
echo $row3['PERS_CODE'];
echo 'Less then 2 years';
echo $row3['PERS_ADD_2'];
echo $row3['PERS_CITY_2'];
echo $row3['PERS_CODE_2'];
echo $row3['PERS_NUMBER'];
echo $row3['PERS_CELL'];
echo $row3['PERS_FAX'];
echo $row3['EMPL_E'];
echo $row3['EMPL_ADD'];
echo $row3['EMPL_CITY'];
echo $row3['EMPL_CODE'];
echo $row3['EMPL_TYPE'];
echo $row3['EMPL_SINCE'];
echo $row3['EMPL_P'];
echo $row3['EMPL_SUP'];
echo $row3['EMPL_N'];
echo $row3['EMPL_GS'];
echo 'Less then 2 years';
echo $row3['EMPL_2_E'];
echo $row3['EMPL_2_ADD'];
echo $row3['EMPL_2_CITY'];
echo $row3['EMPL_2_CODE'];
echo $row3['EMPL_2_TYPE'];

echo $row3['EMPL_2_SINCE'];
echo $row3['EMPL_2_P'];
echo $row3['EMPL_2_SUP'];
echo $row3['EMPL_2_N'];
echo $row3['EMPL_2_GS'];
echo 'Assets & liabilities';
echo $row3['OTHER_OWN_RENT'];
echo $row3['OTHER_OWN_RENT_D'];
echo $row3['OTHER_OWN_RENT_V'];
echo $row3['OTHER_OWN_RENT_AM'];
echo $row3['OTHER_OWN_RENT_MP'];
echo 'Assets & liabilities';
echo $row3['OTHER_CC_REER'];
echo $row3['OTHER_CC_REER_D'];
echo $row3['OTHER_CC_REER_V'];
echo $row3['OTHER_CC_REER_AM'];
echo $row3['OTHER_CC_REER_MP'];
echo 'Assets & liabilities';
echo $row3['OTHER_INV_CAR'];
echo $row3['OTHER_INV_CAR_D'];
echo $row3['OTHER_INV_CAR_V'];
echo $row3['OTHER_INV_CAR_AM'];
echo $row3['OTHER_INV_CAR_MP'];
echo 'Assets & liabilities';
echo $row3['OTHER_OTHER_L'];
echo $row3['OTHER_OTHER_L_D'];
echo $row3['OTHER_OTHER_L_V'];
echo $row3['OTHER_OTHER_L_AM'];
echo $row3['OTHER_OTHER_L_MP'];
echo 'EMAIL';
echo $row3['EMAIL'];
echo 'Accepted therms and conditions';
echo $row3['ACCEPT'];

?>
</body>
</html>
<?php
$vExcelFileName="export". ".doc";
header("Content-type: application/x-ms-download"); //#-- build header to download the excel file
header("Content-Disposition: attachment; filename=$vExcelFileName");
header('Cache-Control: public');
echo "hai";
?>

Link to comment
https://forums.phpfreaks.com/topic/224564-php-to-word/#findComment-1160035
Share on other sites

I haven't tested your code, but if you want to generate .docx or .odt-files from PHP and insert all kinds of variables into a document template, I can very much vouch for 'opentbs', a plugin for the 'TinyButStrong'-templating engine.

 

It is very easy to use: you make a template in f.e. openoffice, in which you place some fields and then you submit some variables to the opentbs-object to generate a new .docx or .odt. Don't go reinventing the wheel :)

 

Zl.

Link to comment
https://forums.phpfreaks.com/topic/224564-php-to-word/#findComment-1160371
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.