Currently I am trying to use the COM functions in PHP to perform a server side mail merge. I have 85 data fields that go into 40 Word files. Each of the 40 files don't have all 85 fields. the most is 40. Originally I wrote word data files and then tried using them. The problem with that was that you are limited to 63 fields. I then tried using tab-delimited text files. This worked perfect except it popped up a box on the servers screen and asked what I was using to deliminate my files. This is the code that I was using:
//Instanciate the word application object
$word = new COM("word.application") or die("Unable to instanciate Word");
//Open the template document
$word->Documents->Open($sourceDocument) or die("Cannot open file!");
//Open the Header Source for the template
//$word->ActiveDocument->MailMerge->OpenHeaderSource("C:\\temp\\mergetable.doc");
$word->ActiveDocument->MailMerge->OpenHeaderSource("C:\\temp\\header.tab");
//Open the Data Source for the template
//$word->ActiveDocument->MailMerge->OpenDataSource("C:\\temp\\tempword.doc");
$word->ActiveDocument->MailMerge->OpenDataSource("C:\\temp\\data.tab");
//Execute the Mail Merge method
$word->ActiveDocument->MailMerge->Execute(False);
This would ultimately be my favorite way of doing it if it's possible to have it automatically detect that the file is tab-deliminated or if there is a way for me to tell it to. If this isn't possible then i will need a way to scrape out all of the fields in a file and use that scraped data to generate a word data file. I found:
$dataFields = $word->ActiveDocument->MailMerge->fields
but don't know how to go any further with it to get the fields accessible by my code. If I add ->Count to the end of it then it tells me how many fields are in the file but I don't know how to get the full list. If someone could help me out here that would be great.
//Instanciate the word application object
$word = new COM("word.application") or die("Unable to instanciate Word");
//Open the template document
$word->Documents->Open($sourceDocument) or die("Cannot open file!");
//Open the Header Source for the template
//$word->ActiveDocument->MailMerge->OpenHeaderSource("C:\\temp\\mergetable.doc");
$word->ActiveDocument->MailMerge->OpenHeaderSource("C:\\temp\\header.tab");
//Open the Data Source for the template
//$word->ActiveDocument->MailMerge->OpenDataSource("C:\\temp\\tempword.doc");
$word->ActiveDocument->MailMerge->OpenDataSource("C:\\temp\\data.tab");
//Execute the Mail Merge method
$word->ActiveDocument->MailMerge->Execute(False);
This would ultimately be my favorite way of doing it if it's possible to have it automatically detect that the file is tab-deliminated or if there is a way for me to tell it to. If this isn't possible then i will need a way to scrape out all of the fields in a file and use that scraped data to generate a word data file. I found:
$dataFields = $word->ActiveDocument->MailMerge->fields
but don't know how to go any further with it to get the fields accessible by my code. If I add ->Count to the end of it then it tells me how many fields are in the file but I don't know how to get the full list. If someone could help me out here that would be great.