note 37972 added to class.com

From: Date: Wed, 03 Dec 2003 17:28:35 +0000
Subject: note 37972 added to class.com
Groups: php.notes 
Request: Send a blank email to php-notes+get-61347@lists.php.net to get a copy of this message
Here's a simple example of printing formatted templates with MS Word. To begin with, I've already built my invoice in Word and saved it as an RTF file. In this case, I'm using "sampleInvoice.php" Fields that will be replaced have been marked as ||CUSTOMER ID|| and so on. $dataText = ""; // open the file if(!($fp= fopen ("C:\wordTest\sampleInvoice.rtf", "r"))) die ("Can't open"); $dataText = fread($fp, 2000000); fclose ($fp); // replace the template fields $dataText = str_replace ("||CUSTOMER ID||",$customerIDValue, $dataText); // save the file as an rtf $timeStamp = time(); $saveFile = "C:/wordTemp/".$timeStamp."-invoice-".$customerIDValue.".rtf"; if(!($fq= fopen ($saveFile, "w+"))) die ("Can't open"); fwrite ($fq, $dataText); fclose ($fq); // initialize the word components $word = new COM("word.application") or die("Unable to instantiate Word"); print "Loaded word version ($word->Version)\n"; $word->visible = true; $word->Documents->Add(); // open the file $word->Documents->Open("$saveFile"); // output the file to the default printer $word->ActiveDocument->PrintOut(1); // shutdown word $word->Quit(); ---- Manual Page -- http://www.php.net/manual/en/class.com.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37972 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37972&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37972&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#61347) next »