note 37972 modified in class.com by vrana
| From: | vrana@php.net | Date: | Thu, 05 Aug 2004 18:11:23 +0000 |
| Subject: | note 37972 modified in class.com by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74034@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.
<?php
$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();
?>
--was--
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();
http://php.net/manual/en/class.com.php