tqla Posted August 9, 2007 Share Posted August 9, 2007 Hi. I am using a script that prints my database to an Avery 5160 formatted PDF file. I need to make one that prints to a Microsoft Word document. Does this sound like something that is even possible? Link to comment https://forums.phpfreaks.com/topic/64164-solved-word-avery-label/ Share on other sites More sharing options...
Fadion Posted August 9, 2007 Share Posted August 9, 2007 U can just use fopen $file = fopen('file.doc', 'w+'); $text = 'Some text here'; fwrite($file, $text); fclose($file); Link to comment https://forums.phpfreaks.com/topic/64164-solved-word-avery-label/#findComment-319759 Share on other sites More sharing options...
tqla Posted August 10, 2007 Author Share Posted August 10, 2007 Thanks GuiltyGear. Is it possible to put a script within the text part. I tried this but got an "parse error, unexpected T_STRING". $file = fopen('file.doc', 'w+'); $text = ' // echo out the results to the screen while ($Fields = mysql_fetch_array($result)) { echo "{$Fields['MCity']} <br>"; } // end while '; fwrite($file, $text); fclose($file); Link to comment https://forums.phpfreaks.com/topic/64164-solved-word-avery-label/#findComment-319886 Share on other sites More sharing options...
Fadion Posted August 10, 2007 Share Posted August 10, 2007 It cant work like that as it interprets all those lines as a string and also u got " inside '. But this may do it: $file = fopen('file.doc', 'w+'); $text = ""; while ($Fields = mysql_fetch_array($result)) { $text .= $Fields['MCity'] . '<br />'; } fwrite($file, $text); fclose($file); It appends the new lines to the $text variable without touching the existing data. Hope it helps. Link to comment https://forums.phpfreaks.com/topic/64164-solved-word-avery-label/#findComment-319891 Share on other sites More sharing options...
Fadion Posted August 10, 2007 Share Posted August 10, 2007 Probably word docs dont understand br and it may print as plaing text. Try using \n or \n\r instead. $text .= $Fields['MCity'] . "\n\r"; Link to comment https://forums.phpfreaks.com/topic/64164-solved-word-avery-label/#findComment-319894 Share on other sites More sharing options...
tqla Posted August 10, 2007 Author Share Posted August 10, 2007 Yay! That works. Thanks for teaching me this GuiltyGear. I appreciate it. Link to comment https://forums.phpfreaks.com/topic/64164-solved-word-avery-label/#findComment-319907 Share on other sites More sharing options...
Fadion Posted August 10, 2007 Share Posted August 10, 2007 Glad it worked Link to comment https://forums.phpfreaks.com/topic/64164-solved-word-avery-label/#findComment-319912 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.